move to SAFE_FREE()
authorSimo Sorce <idra@samba.org>
Mon, 17 Sep 2001 04:52:45 +0000 (04:52 +0000)
committerSimo Sorce <idra@samba.org>
Mon, 17 Sep 2001 04:52:45 +0000 (04:52 +0000)
14 files changed:
source/nsswitch/pam_winbind.h
source/nsswitch/wb_client.c
source/nsswitch/wb_common.c
source/nsswitch/winbind_nss_solaris.c
source/nsswitch/winbindd.c
source/nsswitch/winbindd_cache.c
source/nsswitch/winbindd_glue.c
source/nsswitch/winbindd_group.c
source/nsswitch/winbindd_idmap.c
source/nsswitch/winbindd_misc.c
source/nsswitch/winbindd_nss.h
source/nsswitch/winbindd_user.c
source/nsswitch/winbindd_util.c
source/nsswitch/wins.c

index 5618dc1b61fcb0c8bdf91526215cecb1c47e6948..991c117656ffc8824796dcff68bdabe2ef6d0915 100644 (file)
@@ -68,13 +68,7 @@ do {                             \
  * Don't just free it, forget it too.
  */
 
-#define _pam_drop(X) \
-do {                 \
-    if (X) {         \
-        free(X);     \
-        X=NULL;      \
-    }                \
-} while (0)  
+#define _pam_drop(X) SAFE_FREE(X)
 
 #define  x_strdup(s)  ( (s) ? strdup(s):NULL )     
 #endif
index 12e4bb11db962e07d41bbefcad239bc5cbc75d13..bc76771f9d7ea05ef909d31c60f0c2311e3fbb5e 100644 (file)
@@ -347,7 +347,7 @@ int winbind_initgroups(char *user, gid_t gid)
        /* Free response data if necessary */
 
  done:
-       safe_free(groups);
+       SAFE_FREE(groups);
 
        return result;
 }
@@ -381,7 +381,7 @@ int winbind_getgroups(char *user, int size, gid_t *list)
        }
 
  done:
-       safe_free(groups);
+       SAFE_FREE(groups);
        return result;
 }
 
index 7fb2bc2cf54eb26e28c7bc61a11e6f1ed8314910..0cfefa6f860381f6704fb069401769d323f76f80 100644 (file)
@@ -36,7 +36,7 @@ static char *excluded_domain;
 */
 void winbind_exclude_domain(const char *domain)
 {
-       if (excluded_domain) free(excluded_domain);
+       SAFE_FREE(excluded_domain);
        excluded_domain = strdup(domain);
 }
 
@@ -311,10 +311,8 @@ void free_response(struct winbindd_response *response)
 {
        /* Free any allocated extra_data */
 
-       if (response && response->extra_data) {
-               free(response->extra_data);
-               response->extra_data = NULL;
-       }
+       if (response)
+               SAFE_FREE(response->extra_data);
 }
 
 /* Handle simple types of requests */
index de8a63b90bfb3a46631f1e693c5bcc7cc6fa87fa..9c71c75e9d2d63dadf1f58571a02f76dd562506a 100644 (file)
@@ -117,7 +117,7 @@ _nss_winbind_getpwuid_solwrap(nss_backend_t* be, void* args)
 
 static NSS_STATUS _nss_winbind_passwd_destr (nss_backend_t * be, void *args)
 {
-       free(be);
+       SAFE_FREE(be);
        NSS_DEBUG("_nss_winbind_passwd_destr");
        return NSS_STATUS_SUCCESS;
 }
@@ -241,7 +241,7 @@ _nss_winbind_getgroupsbymember_solwrap(nss_backend_t* be, void* args)
 static NSS_STATUS
 _nss_winbind_group_destr (nss_backend_t* be, void* args)
 {
-       free(be);
+       SAFE_FREE(be);
        NSS_DEBUG("_nss_winbind_group_destr");
        return NSS_STATUS_SUCCESS;
 }
index 713cef312f1fa4d5198dd739d5c09177950e7223..13b84782578749c969ebff5bcc9f86d91cb7e678 100644 (file)
@@ -281,7 +281,7 @@ static void process_request(struct winbindd_cli_state *state)
        /* Free response data - we may be interrupted and receive another
           command before being able to send this data off. */
 
-       safe_free(state->response.extra_data);  
+       SAFE_FREE(state->response.extra_data);  
 
        ZERO_STRUCT(state->response);
 
@@ -363,12 +363,12 @@ static void remove_client(struct winbindd_cli_state *state)
                /* We may have some extra data that was not freed if the
                   client was killed unexpectedly */
 
-               safe_free(state->response.extra_data);
+               SAFE_FREE(state->response.extra_data);
                
                /* Remove from list and free */
                
                DLIST_REMOVE(client_list, state);
-               free(state);
+               SAFE_FREE(state);
                num_clients--;
        }
 }
@@ -454,8 +454,7 @@ static void client_write(struct winbindd_cli_state *state)
                
                state->finished = True;
 
-               safe_free(state->response.extra_data);
-               state->response.extra_data = NULL;
+               SAFE_FREE(state->response.extra_data);
 
                return;
        }
@@ -472,8 +471,7 @@ static void client_write(struct winbindd_cli_state *state)
                
                if (state->write_extra_data) {
 
-                       safe_free(state->response.extra_data);
-                       state->response.extra_data = NULL;
+                       SAFE_FREE(state->response.extra_data);
 
                        state->write_extra_data = False;
 
index 07b1cab58308d365faf4ae080546cb5b193d1207..3fa50abfbab286192407f0eb5757496af891ceb1 100644 (file)
@@ -61,7 +61,7 @@ static uint32 cached_sequence_number(char *domain_name)
                goto refetch;
        }
        memcpy(&rec, dbuf.dptr, sizeof(rec));
-       free(dbuf.dptr);
+       SAFE_FREE(dbuf.dptr);
 
        if (t < (rec.mod_time + lp_winbind_cache_time())) {
                DEBUG(3,("cached sequence number for %s is %u\n",
@@ -359,7 +359,7 @@ static BOOL fetch_cache_entry(char *domain, char *cache_type, char *name,
         
         /* Copy found entry into buffer */        
         memcpy((char *)buf, data.dptr, len < data.dsize ? len : data.dsize);
-       free(data.dptr);
+       SAFE_FREE(data.dptr);
        return True;
 }
 
index 0b721e36d214b7f50739eacd79353658b4f7092e..0c508ccf4b23607c4f464c6ccd0cd484582921a4 100644 (file)
@@ -82,7 +82,7 @@ BOOL wb_lsa_open_policy(char *server, BOOL sec_qos, uint32 des_access,
        if (!NT_STATUS_IS_OK(result) && pol->cli) {
                if (pol->cli->initialised)
                        cli_shutdown(pol->cli);
-               free(pol->cli);
+               SAFE_FREE(pol->cli);
        }
 
        return NT_STATUS_IS_OK(result);
@@ -228,7 +228,7 @@ BOOL wb_samr_connect(char *server, uint32 access_mask, CLI_POLICY_HND *pol)
        if (!NT_STATUS_IS_OK(result) && pol->cli) {
                if (pol->cli->initialised)
                        cli_shutdown(pol->cli);
-               free(pol->cli);
+               SAFE_FREE(pol->cli);
        }
 
        return NT_STATUS_IS_OK(result);
index 55dd41afd4b2f83e494e1b38bb0021bd25834cb3..2b567f13362c3812bdbaa2d0c0896d675b1d9eee 100644 (file)
@@ -173,8 +173,8 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain,
        
        /* Free memory allocated in winbindd_lookup_groupmem() */
        
-       safe_free(name_types);
-       safe_free(rid_mem);
+       SAFE_FREE(name_types);
+       SAFE_FREE(rid_mem);
        
        free_char_array(num_names, names);
        
@@ -489,11 +489,8 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
 
        /* Free any existing group info */
 
-       if (ent->sam_entries) {
-               free(ent->sam_entries);
-               ent->sam_entries = NULL;
-               ent->num_sam_entries = 0;
-       }
+       SAFE_FREE(ent->sam_entries);
+       ent->num_sam_entries = 0;
                
        /* Enumerate domain groups */
                
@@ -522,7 +519,7 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
                               sam_grp_entries, 
                               num_entries * sizeof(struct acct_info));
 
-                       safe_free(sam_grp_entries);
+                       SAFE_FREE(sam_grp_entries);
                }
 
                ent->num_sam_entries += num_entries;
@@ -610,13 +607,13 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
 
                                /* Free state information for this domain */
 
-                               safe_free(ent->sam_entries);
+                               SAFE_FREE(ent->sam_entries);
                                ent->sam_entries = NULL;
 
                                next_ent = ent->next;
                                DLIST_REMOVE(state->getgrent_state, ent);
                                
-                               free(ent);
+                               SAFE_FREE(ent);
                                ent = next_ent;
                        }
 
@@ -676,7 +673,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
 
                        if (!new_gr_mem_list && (group_list[group_list_ndx].num_gr_mem != 0)) {
                                DEBUG(0, ("getgrent(): out of memory\n"));
-                               free(gr_mem_list);
+                               SAFE_FREE(gr_mem_list);
                                gr_mem_list_len = 0;
                                break;
                        }
@@ -689,7 +686,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
                        memcpy(&gr_mem_list[gr_mem_list_len], gr_mem,
                               gr_mem_len);
 
-                       safe_free(gr_mem);
+                       SAFE_FREE(gr_mem);
 
                        group_list[group_list_ndx].gr_mem_ofs = 
                                gr_mem_list_len;
@@ -731,9 +728,8 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
        if (!new_extra_data) {
                DEBUG(0, ("out of memory\n"));
                group_list_ndx = 0;
-               safe_free(state->response.extra_data);
-               state->response.extra_data = NULL;
-               safe_free(gr_mem_list);
+               SAFE_FREE(state->response.extra_data);
+               SAFE_FREE(gr_mem_list);
 
                return WINBINDD_ERROR;
        }
@@ -744,7 +740,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
               [group_list_ndx * sizeof(struct winbindd_gr)], 
               gr_mem_list, gr_mem_list_len);
 
-               safe_free(gr_mem_list);
+               SAFE_FREE(gr_mem_list);
 
        state->response.length += gr_mem_list_len;
 
@@ -840,8 +836,7 @@ enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state)
  
                if (!ted) {
                        DEBUG(0,("winbindd_list_groups: failed to enlarge buffer!\n"));
-                       if (extra_data)
-                               free(extra_data);
+                       SAFE_FREE(extra_data);
                        return WINBINDD_ERROR;
                } else
                        extra_data = ted;
@@ -977,7 +972,7 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state)
        result = WINBINDD_OK;
 
  done:
-       safe_free(user_groups);
+       SAFE_FREE(user_groups);
 
        return result;
 }
index 5f667a621bc3e34c2822b96f8221819f09245e84..8925e947b9a8420d4aa394b94f91f198b8f74d51 100644 (file)
@@ -104,7 +104,7 @@ static BOOL get_id_from_rid(char *domain_name, uint32 rid, uid_t *id,
             result = True;
         }
 
-        free(data.dptr);
+        SAFE_FREE(data.dptr);
 
     } else {
 
@@ -187,7 +187,7 @@ BOOL get_rid_from_id(int id, uint32 *rid, struct winbindd_domain **domain,
             result = True;
         }
     done:            
-        free(data.dptr);
+        SAFE_FREE(data.dptr);
     }
 
     return result;
index 618dd6f1c9d79e8a568f00bb7ef9600c1f83a250..620dc9e7d9ba6eb379f8fc0ca88740c9cb40cb4a 100644 (file)
@@ -55,7 +55,7 @@ static BOOL _get_trust_account_password(char *domain, unsigned char *ret_pwd,
 
        if (pass_last_set_time) *pass_last_set_time = pass->mod_time;
        memcpy(ret_pwd, pass->hash, 16);
-       free(pass);
+       SAFE_FREE(pass);
        return True;
 }
 
@@ -152,7 +152,7 @@ enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
 
                if (!ted) {
                        DEBUG(0,("winbindd_list_trusted_domains: failed to enlarge buffer!\n"));
-                       if (extra_data) free(extra_data);
+                       SAFE_FREE(extra_data);
                        return WINBINDD_ERROR;
                }
                else extra_data = ted;
index ed7a0d4a28ba79b6d282541d0b404bbaea7cdedd..20667b0a9bd273ce3eec07f5f345b611ff11b4ed 100644 (file)
    Boston, MA  02111-1307, USA.   
 */
 
+#ifndef SAFE_FREE
+#define SAFE_FREE(x) do { if(x) {free(x); x=NULL;} } while(0)
+#endif
+
 #ifndef _WINBINDD_NTDOM_H
 #define _WINBINDD_NTDOM_H
 
index 9e0c1e834446c8412e8791bbaca6d7ca1860eddc..aa138cfdeb7a8c526771c86c4672cdb390179332 100644 (file)
@@ -398,12 +398,9 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
 
        /* Free any existing user info */
 
-       if (ent->sam_entries) {
-               free(ent->sam_entries);
-               ent->sam_entries = NULL;
-               ent->num_sam_entries = 0;
-       }
-
+       SAFE_FREE(ent->sam_entries);
+       ent->num_sam_entries = 0;
+       
        /* Call query_dispinfo to get a list of usernames and user rids */
 
        do {
@@ -425,8 +422,7 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
 
                        if (!tnl) {
                                DEBUG(0,("get_sam_user_entries: Realloc failed.\n"));
-                               if (name_list)
-                                       free(name_list);
+                               SAFE_FREE(name_list);
                                return WINBINDD_ERROR;
                        } else
                                name_list = tnl;
@@ -535,13 +531,12 @@ enum winbindd_result winbindd_getpwent(struct winbindd_cli_state *state)
 
                                /* Free state information for this domain */
 
-                               safe_free(ent->sam_entries);
-                               ent->sam_entries = NULL;
+                               SAFE_FREE(ent->sam_entries);
 
                                next_ent = ent->next;
                                DLIST_REMOVE(state->getpwent_state, ent);
 
-                               free(ent);
+                               SAFE_FREE(ent);
                                ent = next_ent;
                        }
  
@@ -653,7 +648,7 @@ enum winbindd_result winbindd_list_users(struct winbindd_cli_state *state)
                        
                        if (!ted) {
                                DEBUG(0,("winbindd_list_users: failed to enlarge buffer!\n"));
-                               if (extra_data) free(extra_data);
+                               SAFE_FREE(extra_data);
                                return WINBINDD_ERROR;
                        }
                        else extra_data = ted;
index 7059f268cab013fd1fc8c448d7d063ce199d3101..86517c4e2da832535161bb73b095a8ec6c7ebd7e 100644 (file)
@@ -297,7 +297,7 @@ void winbindd_kill_all_connections(void)
 
                next = domain->next;
                DLIST_REMOVE(domain_list, domain);
-               free(domain);
+               SAFE_FREE(domain);
 
                domain = next;
        }
@@ -326,7 +326,7 @@ static BOOL get_any_dc_name(char *domain, fstring srv_name)
        
  got_ip:
        dc_ip = ip_list[i];
-       free(ip_list);
+       SAFE_FREE(ip_list);
                
        if (!lookup_pdc_name(global_myname, domain, &dc_ip, srv_name))
                return False;
@@ -682,11 +682,11 @@ void free_getent_state(struct getent_state *state)
 
         /* Free sam entries then list entry */
 
-        safe_free(state->sam_entries);
+        SAFE_FREE(state->sam_entries);
         DLIST_REMOVE(state, state);
         next = temp->next;
 
-        free(temp);
+        SAFE_FREE(temp);
         temp = next;
     }
 }
index bfd1835b4e533ab5bba162d7e8bdc90e2a501bf9..c4485ca03af5c2c530a6f27aad4495606131dfb8 100644 (file)
@@ -167,8 +167,7 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he,
                host_addresses++;
        }
 
-       if (ip_list)
-               free(ip_list);
+       SAFE_FREE(ip_list);
 
        memcpy(buffer, name, namelen);
        he->h_name = buffer;