r21608: Fix a couple of memleaks in error code paths before
authorJeremy Allison <jra@samba.org>
Thu, 1 Mar 2007 01:17:36 +0000 (01:17 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:18:16 +0000 (12:18 -0500)
Coverity finds them :-)
Jeremy.

source/libads/ldap.c
source/passdb/pdb_ldap.c
source/utils/net_ads.c

index e9d8bf6bbf283bfd1b30c85ff617e7de484bc358..1d08a01a26389c7fb1ce1af44de0413b4bb1c15f 100644 (file)
@@ -1635,7 +1635,7 @@ ADS_STATUS ads_create_machine_acct(ADS_STRUCT *ads, const char *machine_name,
        char *samAccountName, *controlstr;
        TALLOC_CTX *ctx;
        ADS_MODLIST mods;
-       char *machine_escaped;
+       char *machine_escaped = NULL;
        char *new_dn;
        const char *objectClass[] = {"top", "person", "organizationalPerson",
                                     "user", "computer", NULL};
@@ -1681,6 +1681,7 @@ ADS_STATUS ads_create_machine_acct(ADS_STRUCT *ads, const char *machine_name,
        ret = ads_gen_add(ads, new_dn, mods);
 
 done:
+       SAFE_FREE(machine_escaped);
        ads_msgfree(ads, res);
        talloc_destroy(ctx);
        
index 4edffe97d9f975dfeb7f5c5d213f16fc0f874649..5fd607a7fce88edb027e696226d2deda8e30a6cd 100644 (file)
@@ -2436,6 +2436,7 @@ static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
                        
                        filter = talloc_asprintf_append(filter, "(uid=%s)", escape_memberuid);
                        if (filter == NULL) {
+                               SAFE_FREE(escape_memberuid);
                                ret = NT_STATUS_NO_MEMORY;
                                goto done;
                        }
index cb5b08c672e9062e52e9f05e2234589d2b245308..b1ac40fd72e4e3dd859cf9278c5fc1655afe6dc2 100644 (file)
@@ -1819,7 +1819,7 @@ static int net_ads_printer_publish(int argc, const char **argv)
        TALLOC_CTX *mem_ctx = talloc_init("net_ads_printer_publish");
        ADS_MODLIST mods = ads_init_mods(mem_ctx);
        char *prt_dn, *srv_dn, **srv_cn;
-       char *srv_cn_escaped, *printername_escaped;
+       char *srv_cn_escaped = NULL, *printername_escaped = NULL;
        LDAPMessage *res = NULL;
 
        if (!ADS_ERR_OK(ads_startup(True, &ads))) {
@@ -1874,6 +1874,8 @@ static int net_ads_printer_publish(int argc, const char **argv)
        srv_cn_escaped = escape_rdn_val_string_alloc(srv_cn[0]);
        printername_escaped = escape_rdn_val_string_alloc(printername);
        if (!srv_cn_escaped || !printername_escaped) {
+               SAFE_FREE(srv_cn_escaped);
+               SAFE_FREE(printername_escaped);
                d_fprintf(stderr, "Internal error, out of memory!");
                ads_destroy(&ads);
                return -1;
@@ -1881,16 +1883,21 @@ static int net_ads_printer_publish(int argc, const char **argv)
 
        asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_escaped, printername_escaped, srv_dn);
 
+       SAFE_FREE(srv_cn_escaped);
+       SAFE_FREE(printername_escaped);
+
        pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SPOOLSS, &nt_status);
        if (!pipe_hnd) {
                d_fprintf(stderr, "Unable to open a connnection to the spoolss pipe on %s\n",
                         servername);
+               SAFE_FREE(prt_dn);
                ads_destroy(&ads);
                return -1;
        }
 
        if (!W_ERROR_IS_OK(get_remote_printer_publishing_data(pipe_hnd, mem_ctx, &mods,
                                                              printername))) {
+               SAFE_FREE(prt_dn);
                ads_destroy(&ads);
                return -1;
        }
@@ -1898,11 +1905,13 @@ static int net_ads_printer_publish(int argc, const char **argv)
         rc = ads_add_printer_entry(ads, prt_dn, mem_ctx, &mods);
         if (!ADS_ERR_OK(rc)) {
                 d_fprintf(stderr, "ads_publish_printer: %s\n", ads_errstr(rc));
+               SAFE_FREE(prt_dn);
                ads_destroy(&ads);
                 return -1;
         }
  
         d_printf("published printer\n");
+       SAFE_FREE(prt_dn);
        ads_destroy(&ads);
  
        return 0;