utils: Free host realm after processing
authorSwen Schillig <swen@linux.ibm.com>
Wed, 21 Nov 2018 12:30:08 +0000 (13:30 +0100)
committerRalph Boehme <slow@samba.org>
Thu, 22 Nov 2018 10:18:41 +0000 (11:18 +0100)
In case of error and at the end of processing the list
of realms have to be free'd again.

Signed-off-by: Swen Schillig <swen@linux.ibm.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Thu Nov 22 11:18:41 CET 2018 on sn-devel-144

source3/utils/net_lookup.c

index f94af266daa2a33df1d74dd62c944d40dfc97876..140f9900795e5c029f98d6f41ddf8a0a9b56cb7c 100644 (file)
@@ -281,6 +281,7 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
        krb5_context ctx;
        struct ip_service *kdcs;
        const char *realm;
+       char **get_host_realms = NULL;
        int num_kdcs = 0;
        int i;
        NTSTATUS status;
@@ -298,21 +299,20 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
        } else if (lp_realm() && *lp_realm()) {
                realm = lp_realm();
        } else {
-               char **realms;
-
-               rc = krb5_get_host_realm(ctx, NULL, &realms);
+               rc = krb5_get_host_realm(ctx, NULL, &get_host_realms);
                if (rc) {
                        DEBUG(1,("krb5_gethost_realm failed (%s)\n",
                                 error_message(rc)));
                        krb5_free_context(ctx);
                        return -1;
                }
-               realm = (const char *) *realms;
+               realm = (const char *) *get_host_realms;
        }
 
        status = get_kdc_list(realm, NULL, &kdcs, &num_kdcs);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1,("get_kdc_list failed (%s)\n", nt_errstr(status)));
+               krb5_free_host_realm(ctx, get_host_realms);
                krb5_free_context(ctx);
                return -1;
        }
@@ -325,6 +325,7 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
                d_printf("%s:%u\n", addr, kdcs[i].port);
        }
 
+       krb5_free_host_realm(ctx, get_host_realms);
        krb5_free_context(ctx);
        return 0;
 #endif