Make sure that wbcLookupSid() and wbcLookupRids() use talloc()'d memory.
authorGerald (Jerry) Carter <jerry@samba.org>
Wed, 2 Jan 2008 20:50:59 +0000 (14:50 -0600)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 2 Jan 2008 20:50:59 +0000 (14:50 -0600)
Follows existing convention that all returned memory should be freed with
wbcFreeMemory() and not directly with free().  Noticed by Volker.  Txs.
(This used to be commit 39c2059f66ee9eb471a503b9c776807b91c2a8f8)

source3/lib/winbind_util.c
source3/nsswitch/libwbclient/wbc_sid.c
source3/nsswitch/libwbclient/wbc_util.c

index f51a0171a23998e4b1f6950cd94cd536c5e729a3..2cabf5bcacf45e5c7a43bd505c793c1160ba01d8 100644 (file)
@@ -74,8 +74,8 @@ bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
        DEBUG(10, ("winbind_lookup_sid: SUCCESS: SID %s -> %s %s\n", 
                   sid_string_dbg(sid), domain_name, account_name));
 
        DEBUG(10, ("winbind_lookup_sid: SUCCESS: SID %s -> %s %s\n", 
                   sid_string_dbg(sid), domain_name, account_name));
 
-       SAFE_FREE(domain_name);
-       SAFE_FREE(account_name);
+       wbcFreeMemory(domain_name);
+       wbcFreeMemory(account_name);
        
        if ((domain && !*domain) || (name && !*name)) {         
                DEBUG(0,("winbind_lookup_sid: talloc() failed!\n"));
        
        if ((domain && !*domain) || (name && !*name)) {         
                DEBUG(0,("winbind_lookup_sid: talloc() failed!\n"));
@@ -192,8 +192,9 @@ bool winbind_lookup_rids(TALLOC_CTX *mem_ctx,
        
        ret = wbcLookupRids(&dom_sid, num_rids, rids,
                            &dom_name, &namelist, &name_types);
        
        ret = wbcLookupRids(&dom_sid, num_rids, rids,
                            &dom_name, &namelist, &name_types);
-       if (ret != WBC_ERR_SUCCESS)
+       if (ret != WBC_ERR_SUCCESS) {           
                return False;
                return False;
+       }       
        
        *domain_name = talloc_strdup(mem_ctx, dom_name);
        *names       = TALLOC_ARRAY(mem_ctx, const char*, num_rids);
        
        *domain_name = talloc_strdup(mem_ctx, dom_name);
        *names       = TALLOC_ARRAY(mem_ctx, const char*, num_rids);
@@ -202,11 +203,11 @@ bool winbind_lookup_rids(TALLOC_CTX *mem_ctx,
        for(i=0; i<num_rids; i++) {
                (*names)[i] = talloc_strdup(names, namelist[i]);
                (*types)[i] = (enum lsa_SidType)name_types[i];
        for(i=0; i<num_rids; i++) {
                (*names)[i] = talloc_strdup(names, namelist[i]);
                (*types)[i] = (enum lsa_SidType)name_types[i];
-
-               free(CONST_DISCARD(char*, namelist[i]));                
        }
        }
-       free(namelist);
-       free(name_types);
+
+       wbcFreeMemory(CONST_DISCARD(char*, dom_name));
+       wbcFreeMemory(namelist);
+       wbcFreeMemory(name_types);
        
        return True;    
 }
        
        return True;    
 }
index c877e1d9d4df1359b7e762428ea143cf3b167195..8311a21a86c8e60fea37b3bae6cd64b43bb10381 100644 (file)
@@ -265,12 +265,12 @@ wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
        /* Copy out result */
 
        if (domain != NULL) {
        /* Copy out result */
 
        if (domain != NULL) {
-               *domain = strdup(response.data.name.dom_name);
+               *domain = talloc_strdup(NULL, response.data.name.dom_name);
                BAIL_ON_PTR_ERROR((*domain), wbc_status);
        }
 
        if (name != NULL) {
                BAIL_ON_PTR_ERROR((*domain), wbc_status);
        }
 
        if (name != NULL) {
-               *name = strdup(response.data.name.name);
+               *name = talloc_strdup(NULL, response.data.name.name);
                BAIL_ON_PTR_ERROR((*name), wbc_status);
        }
 
                BAIL_ON_PTR_ERROR((*name), wbc_status);
        }
 
@@ -283,9 +283,9 @@ wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
  done:
        if (!WBC_ERROR_IS_OK(wbc_status)) {
                if (*domain)
  done:
        if (!WBC_ERROR_IS_OK(wbc_status)) {
                if (*domain)
-                       free(*domain);
+                       talloc_free(*domain);
                if (*name)
                if (*name)
-                       free(*name);
+                       talloc_free(*name);
        }
 
        return wbc_status;
        }
 
        return wbc_status;
@@ -334,11 +334,9 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
 
        ridbuf_size = (sizeof(char)*11) * num_rids + 1;
 
 
        ridbuf_size = (sizeof(char)*11) * num_rids + 1;
 
-       ridlist = malloc(ridbuf_size);
+       ridlist = talloc_zero_array(NULL, char, ridbuf_size);
        BAIL_ON_PTR_ERROR(ridlist, wbc_status);
 
        BAIL_ON_PTR_ERROR(ridlist, wbc_status);
 
-       memset(ridlist, 0x0, ridbuf_size);
-
        len = 0;
        for (i=0; i<num_rids && (len-1)>0; i++) {
                char ridstr[12];
        len = 0;
        for (i=0; i<num_rids && (len-1)>0; i++) {
                char ridstr[12];
@@ -356,15 +354,15 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
        wbc_status = wbcRequestResponse(WINBINDD_LOOKUPRIDS,
                                        &request,
                                        &response);
        wbc_status = wbcRequestResponse(WINBINDD_LOOKUPRIDS,
                                        &request,
                                        &response);
-       free(ridlist);
+       talloc_free(ridlist);
 
 
-       domain_name = strdup(response.data.domain_name);
+       domain_name = talloc_strdup(NULL, response.data.domain_name);
        BAIL_ON_PTR_ERROR(domain_name, wbc_status);
 
        BAIL_ON_PTR_ERROR(domain_name, wbc_status);
 
-       *names = (const char**)malloc(sizeof(char*) * num_rids);
+       *names = talloc_array(NULL, const char*, num_rids);
        BAIL_ON_PTR_ERROR((*names), wbc_status);
 
        BAIL_ON_PTR_ERROR((*names), wbc_status);
 
-       *types = (enum wbcSidType*)malloc(sizeof(enum wbcSidType) * num_rids);
+       *types = talloc_array(NULL, enum wbcSidType, num_rids);
        BAIL_ON_PTR_ERROR((*types), wbc_status);
 
        p = (char *)response.extra_data.data;
        BAIL_ON_PTR_ERROR((*types), wbc_status);
 
        p = (char *)response.extra_data.data;
@@ -393,7 +391,8 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
 
                *q = '\0';
 
 
                *q = '\0';
 
-               (*names)[i] = strdup(p);
+               (*names)[i] = talloc_strdup((*names), p);
+               BAIL_ON_PTR_ERROR(((*names)[i]), wbc_status);           
 
                p = q+1;
        }
 
                p = q+1;
        }
@@ -403,21 +402,23 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
                BAIL_ON_WBC_ERROR(wbc_status);
        }
 
                BAIL_ON_WBC_ERROR(wbc_status);
        }
 
-       free(response.extra_data.data);
-
        wbc_status = WBC_ERR_SUCCESS;
 
  done:
        wbc_status = WBC_ERR_SUCCESS;
 
  done:
+       if (response.extra_data.data) {         
+               free(response.extra_data.data);
+       }       
+               
        if (!WBC_ERROR_IS_OK(wbc_status)) {
                if (domain_name)
        if (!WBC_ERROR_IS_OK(wbc_status)) {
                if (domain_name)
-                       free(domain_name);
+                       talloc_free(domain_name);
                if (*names)
                if (*names)
-                       free(*names);
+                       talloc_free(*names);
                if (*types)
                if (*types)
-                       free(*types);
+                       talloc_free(*types);
        } else {
                *pp_domain_name = domain_name;
        }
 
        return wbc_status;
        } else {
                *pp_domain_name = domain_name;
        }
 
        return wbc_status;
-}
+} 
index c6acb27e558e67ef14ee8107f548810d1a68bf5a..7eb19731a7917553ad11f8c865c810bbe9fade09 100644 (file)
@@ -51,10 +51,6 @@ wbcErr wbcPing(void)
  *
  * @return #wbcErr
  *
  *
  * @return #wbcErr
  *
- * The char* members of the struct wbcDomainInfo* are malloc()'d
- * and it the the responsibility of the caller to free the members
- * before  discarding the struct.
- *
  **/
 
 
  **/