move to SAFE_FREE()
authorSimo Sorce <idra@samba.org>
Mon, 17 Sep 2001 02:19:44 +0000 (02:19 +0000)
committerSimo Sorce <idra@samba.org>
Mon, 17 Sep 2001 02:19:44 +0000 (02:19 +0000)
23 files changed:
source/lib/access.c
source/lib/bitmap.c
source/lib/cmd_interp.c
source/lib/dprintf.c
source/lib/genrand.c
source/lib/hash.c
source/lib/iconv.c
source/lib/interface.c
source/lib/messages.c
source/lib/replace.c
source/lib/sysacls.c
source/lib/system.c
source/lib/talloc.c
source/lib/time.c
source/lib/username.c
source/lib/util.c
source/lib/util_array.c
source/lib/util_file.c
source/lib/util_getent.c
source/lib/util_list.c
source/lib/util_str.c
source/lib/wins_srv.c
source/lib/xfile.c

index 99f3cc49b519681230b477d7b0ac8537abea41fb..b3d183848406ef9e7fadec106b56a29b26a883d0 100644 (file)
@@ -85,7 +85,7 @@ static int string_match(char *tok,char *s, char *invalid_char)
                         tok+1,
                         BOOLSTR(netgroup_ok)));
 
-               free(hostname);
+               SAFE_FREE(hostname);
       
                if (netgroup_ok) return(True);
 #else
index 7625f529095e9ee04549862a230eeb07b0677a70..2ae9defb2d58e406e735b1f4bb915db941462db5 100644 (file)
@@ -41,7 +41,7 @@ struct bitmap *bitmap_allocate(int n)
        bm->n = n;
        bm->b = (uint32 *)malloc(sizeof(bm->b[0])*(n+31)/32);
        if (!bm->b) {
-               free(bm);
+               SAFE_FREE(bm);
                return NULL;
        }
 
@@ -59,10 +59,8 @@ void bitmap_free(struct bitmap *bm)
        if (!bm)
                return;
 
-       if(bm->b)
-               free(bm->b);
-
-       free(bm);
+       SAFE_FREE(bm->b);
+       SAFE_FREE(bm);
 }
 
 /****************************************************************************
index 62e361408b8457eb99fede0c077f089e6ab7b983..5ebb8a94d2258361879873914f954bb7a4482012 100644 (file)
@@ -66,9 +66,9 @@ FILE *out_hnd;
 static void cmd_set_free(struct command_set *item)
 {
        if (item != NULL)
-               safe_free(item->name);
+               SAFE_FREE(item->name);
 
-       safe_free(item);
+       SAFE_FREE(item);
 }
 
 static struct command_set *cmd_set_dup(const struct command_set *from)
@@ -432,7 +432,7 @@ static uint32 process(struct client_info *info, char *cmd_str)
 
                        if (!(ret_line = readline(pline)))
                                break;
-                       safe_free(ret_line);
+                       SAFE_FREE(ret_line);
 
                        /* Copy read line to samba buffer */
 
index 157ce6b716f94a0ad5232c63b5e7ec9d1625e4dd..964d63c72ffaa6a7f112d47e9069bbdfd944b26b 100644 (file)
@@ -47,7 +47,7 @@ int d_vfprintf(FILE *f, const char *format, va_list ap)
 again:
        p2 = malloc(maxlen);
        if (!p2) {
-               free(p);
+               SAFE_FREE(p);
                return -1;
        }
        clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen);
@@ -55,14 +55,14 @@ again:
        if (clen >= maxlen) {
                /* it didn't fit - try a larger buffer */
                maxlen *= 2;
-               free(p2);
+               SAFE_FREE(p2);
                goto again;
        }
 
        /* good, its converted OK */
-       free(p);
+       SAFE_FREE(p);
        ret = fwrite(p2, 1, clen, f);
-       free(p2);
+       SAFE_FREE(p2);
 
        return ret;
 }
index d5556149af48ef94fd0f230b3fd4a5427181b29c..c4fb925a75b1065acb32068623359f3a3aa2adce 100644 (file)
@@ -37,8 +37,7 @@ size_t reseed_data_size;
 
 void set_rand_reseed_data(unsigned char *data, size_t len)
 {
-       if (reseed_data)
-               free(reseed_data);
+       SAFE_FREE(reseed_data);
        reseed_data_size = 0;
 
        reseed_data = (unsigned char *)memdup(data, len);
index 92840a4c983e7317b40f7ce13fd592aa5536518e..6c81931152a642824d2d2da0b6faf383ef6192f0 100644 (file)
@@ -192,8 +192,8 @@ hash_element *hash_insert(hash_table *table, char *value, char *key)
                bucket = hash_elem->bucket;
                ubi_dlRemThis(&(table->lru_chain), &(hash_elem->lru_link.lru_link));
                ubi_dlRemThis(bucket, (ubi_dlNodePtr)hash_elem);
-               free((char*)(hash_elem->value));
-               free(hash_elem);
+               SAFE_FREE((char*)(hash_elem->value));
+               SAFE_FREE(hash_elem);
        }  else  {
                table->num_elements += 1;
        }
@@ -238,10 +238,8 @@ void hash_remove(hash_table *table, hash_element *hash_elem)
        if (hash_elem) { 
                ubi_dlRemove(&(table->lru_chain), &(hash_elem->lru_link.lru_link));
                ubi_dlRemove(hash_elem->bucket, (ubi_dlNodePtr) hash_elem);
-               if(hash_elem->value)
-                       free((char *)(hash_elem->value));
-               if(hash_elem)
-                       free((char *) hash_elem);
+               SAFE_FREE(hash_elem->value);
+               SAFE_FREE(hash_elem);
                table->num_elements--;
        }
 }
@@ -285,8 +283,7 @@ static BOOL enlarge_hash_table(hash_table *table)
                        table->num_elements++;
                }
        }
-       if(buckets)
-               free((char *) buckets);
+       SAFE_FREE(buckets);
 
        return True;
 }
@@ -309,14 +306,11 @@ void hash_clear(hash_table *table)
        for (i = 0; i < table->size; bucket++, i++) {
                while (bucket->count != 0) {
                        hash_elem = (hash_element *) ubi_dlRemHead(bucket);
-                       if(hash_elem->value)
-                               free((char *)(hash_elem->value));
-                       if(hash_elem)
-                               free((char *)hash_elem);
+                       SAFE_FREE(hash_elem->value);
+                       SAFE_FREE(hash_elem);
                }
        }
        table->size = 0;
-       if(table->buckets)
-               free((char *) table->buckets);
+       SAFE_FREE(table->buckets);
        table->buckets = NULL;
 }
index 46507dd6247b319a9ced4d7ac6826d20284a3756..a8962726e04076214d6b1bfc5050255835d31d15 100644 (file)
@@ -186,7 +186,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
        return ret;
 
 failed:
-       free(ret);
+       SAFE_FREE(ret);
        errno = EINVAL;
        return (smb_iconv_t)-1;
 }
@@ -203,7 +203,7 @@ int smb_iconv_close (smb_iconv_t cd)
 #endif
 
        memset(cd, 0, sizeof(*cd));
-       free(cd);
+       SAFE_FREE(cd);
        return 0;
 }
 
index c89c22aa081740e61b8212bb5355ab12d0cba515..c68b405f7c7c48b3b829e27a1198416133b05dc1 100644 (file)
@@ -178,17 +178,14 @@ void load_interfaces(void)
        allones_ip = *interpret_addr2("255.255.255.255");
        loopback_ip = *interpret_addr2("127.0.0.1");
 
-       if (probed_ifaces) {
-               free(probed_ifaces);
-               probed_ifaces = NULL;
-       }
+       SAFE_FREE(probed_ifaces);
 
        /* dump the current interfaces if any */
        while (local_interfaces) {
                struct interface *iface = local_interfaces;
                DLIST_REMOVE(local_interfaces, local_interfaces);
                ZERO_STRUCTPN(iface);
-               free(iface);
+               SAFE_FREE(iface);
        }
 
        /* probe the kernel for interfaces */
index 18f9d0c1d50be2c53a370b1604865766b268bd54..5e7072c2b4d1beea5f18f02510364fb993b8ab97 100644 (file)
@@ -175,7 +175,7 @@ BOOL message_send_pid(pid_t pid, int msg_type, void *buf, size_t len, BOOL dupli
                dbuf.dptr = p;
                dbuf.dsize = len + sizeof(rec);
                tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
-               free(p);
+               SAFE_FREE(p);
                goto ok;
        }
 
@@ -193,7 +193,7 @@ BOOL message_send_pid(pid_t pid, int msg_type, void *buf, size_t len, BOOL dupli
                        if (!memcmp(ptr, &rec, sizeof(rec))) {
                                if (!len || (len && !memcmp( ptr + sizeof(rec), (char *)buf, len))) {
                                        DEBUG(10,("message_send_pid: discarding duplicate message.\n"));
-                                       free(dbuf.dptr);
+                                       SAFE_FREE(dbuf.dptr);
                                        tdb_chainunlock(tdb, kbuf);
                                        return True;
                                }
@@ -211,11 +211,11 @@ BOOL message_send_pid(pid_t pid, int msg_type, void *buf, size_t len, BOOL dupli
        memcpy((void *)((char*)p+dbuf.dsize), &rec, sizeof(rec));
        if (len > 0) memcpy((void *)((char*)p+dbuf.dsize+sizeof(rec)), buf, len);
 
-       free(dbuf.dptr);
+       SAFE_FREE(dbuf.dptr);
        dbuf.dptr = p;
        dbuf.dsize += len + sizeof(rec);
        tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
-       free(dbuf.dptr);
+       SAFE_FREE(dbuf.dptr);
 
  ok:
        tdb_chainunlock(tdb, kbuf);
@@ -275,7 +275,7 @@ static BOOL message_recv(int *msg_type, pid_t *src, void **buf, size_t *len)
        else
                tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
 
-       free(dbuf.dptr);
+       SAFE_FREE(dbuf.dptr);
        tdb_chainunlock(tdb, kbuf);
        return True;
 
@@ -307,7 +307,7 @@ void message_dispatch(void)
                                dfn->fn(msg_type, src, buf, len);
                        }
                }
-               if (buf) free(buf);
+               SAFE_FREE(buf);
        }
 }
 
@@ -348,7 +348,7 @@ void message_deregister(int msg_type)
                next = dfn->next;
                if (dfn->msg_type == msg_type) {
                        DLIST_REMOVE(dispatch_fns, dfn);
-                       free(dfn);
+                       SAFE_FREE(dfn);
                }
        }       
 }
index 45c302f498aad4ebf1e0b5ac97f4b254dc1a73a4..e1871a6f558d9394f1333689e50be222af62f7fa 100644 (file)
@@ -194,7 +194,7 @@ Corrections by richard.kettlewell@kewill.com
        }
        endgrent();
        ret = sys_setgroups(i,grouplst);
-       free((char *)grouplst);
+       SAFE_FREE(grouplst);
        return ret;
 #endif /* HAVE_SETGROUPS */
 }
index 424e705755389b3838605801b0d9d6c69bc7b6ae..1c840d84ca3b2ebce4cf4643b5144baa8b654a6f 100644 (file)
@@ -700,7 +700,7 @@ char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
                        maxlen += nbytes + 20 * (acl_d->count - i);
 
                        if ((text = Realloc(oldtext, maxlen)) == NULL) {
-                               free(oldtext);
+                               SAFE_FREE(oldtext);
                                errno = ENOMEM;
                                return NULL;
                        }
@@ -928,9 +928,7 @@ int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
 
        ret = acl(name, SETACL, acl_count, acl_p);
 
-       if (acl_buf) {
-               free(acl_buf);
-       }
+       SAFE_FREE(acl_buf);
 
        return ret;
 }
@@ -966,13 +964,13 @@ int sys_acl_delete_def_file(const char *path)
 
 int sys_acl_free_text(char *text)
 {
-       free(text);
+       SAFE_FREE(text);
        return 0;
 }
 
 int sys_acl_free_acl(SMB_ACL_T acl_d) 
 {
-       free(acl_d);
+       SAFE_FREE(acl_d);
        return 0;
 }
 
@@ -1047,7 +1045,7 @@ SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
                return NULL;
        }
        if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
-               free(a);
+               SAFE_FREE(a);
                return NULL;
        }
        a->next = -1;
@@ -1064,7 +1062,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
                return NULL;
        }
        if ((a->aclp = acl_get_fd(fd)) == NULL) {
-               free(a);
+               SAFE_FREE(a);
                return NULL;
        }
        a->next = -1;
@@ -1355,7 +1353,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
        rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
        if(rc == -1) {
                DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
-               free(file_acl);
+               SAFE_FREE(file_acl);
                return(NULL);
        }
 
@@ -1375,7 +1373,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
 
        acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
        if(acl_entry_link->entryp == NULL) {
-               free(file_acl);
+               SAFE_FREE(file_acl);
                errno = ENOMEM;
                DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
                return(NULL);
@@ -1412,7 +1410,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
                                                                                        malloc(sizeof(struct acl_entry_link));
 
                                if(acl_entry_link->nextp == NULL) {
-                                       free(file_acl);
+                                       SAFE_FREE(file_acl);
                                        errno = ENOMEM;
                                        DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
                                        return(NULL);
@@ -1422,7 +1420,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
                                acl_entry_link = acl_entry_link->nextp;
                                acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
                                if(acl_entry_link->entryp == NULL) {
-                                       free(file_acl);
+                                       SAFE_FREE(file_acl);
                                        errno = ENOMEM;
                                        DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
                                        return(NULL);
@@ -1481,7 +1479,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
                if(acl_entry_link_head->count != 0) {
                        acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
                        if(acl_entry_link->nextp == NULL) {
-                               free(file_acl);
+                               SAFE_FREE(file_acl);
                                errno = ENOMEM;
                                DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
                                return(NULL);
@@ -1491,7 +1489,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
                        acl_entry_link = acl_entry_link->nextp;
                        acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
                        if(acl_entry_link->entryp == NULL) {
-                               free(file_acl);
+                               SAFE_FREE(file_acl);
                                errno = ENOMEM;
                                DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
                                return(NULL);
@@ -1535,7 +1533,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
        }
 
        acl_entry_link_head->count = 0;
-       free(file_acl);
+       SAFE_FREE(file_acl);
 
        return(acl_entry_link_head);
 }
@@ -1569,7 +1567,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
        rc = fstatacl(fd,0,file_acl,BUFSIZ);
        if(rc == -1) {
                DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
-               free(file_acl);
+               SAFE_FREE(file_acl);
                return(NULL);
        }
 
@@ -1585,7 +1583,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
 
        acl_entry_link_head = acl_entry_link = sys_acl_init(0);
        if(acl_entry_link_head == NULL){
-               free(file_acl);
+               SAFE_FREE(file_acl);
                return(NULL);
        }
 
@@ -1594,7 +1592,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
        if(acl_entry_link->entryp == NULL) {
                errno = ENOMEM;
                DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
-               free(file_acl);
+               SAFE_FREE(file_acl);
                return(NULL);
        }
 
@@ -1630,7 +1628,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
                                if(acl_entry_link->nextp == NULL) {
                                        errno = ENOMEM;
                                        DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
-                                       free(file_acl);
+                                       SAFE_FREE(file_acl);
                                        return(NULL);
                                }
                                acl_entry_link->nextp->prevp = acl_entry_link;
@@ -1639,7 +1637,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
                                if(acl_entry_link->entryp == NULL) {
                                        errno = ENOMEM;
                                        DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
-                                       free(file_acl);
+                                       SAFE_FREE(file_acl);
                                        return(NULL);
                                }
 
@@ -1698,7 +1696,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
                        if(acl_entry_link->nextp == NULL) {
                                errno = ENOMEM;
                                DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
-                               free(file_acl);
+                               SAFE_FREE(file_acl);
                                return(NULL);
                        }
 
@@ -1707,7 +1705,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
                        acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
 
                        if(acl_entry_link->entryp == NULL) {
-                               free(file_acl);
+                               SAFE_FREE(file_acl);
                                errno = ENOMEM;
                                DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
                                return(NULL);
@@ -1750,7 +1748,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
        }
 
        acl_entry_link_head->count = 0;
-       free(file_acl);
+       SAFE_FREE(file_acl);
  
        return(acl_entry_link_head);
 }
@@ -1955,14 +1953,14 @@ int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl
                        acl_length += sizeof(struct acl_entry);
                        file_acl_temp = (struct acl *)malloc(acl_length);
                        if(file_acl_temp == NULL) {
-                               free(file_acl);
+                               SAFE_FREE(file_acl);
                                errno = ENOMEM;
                                DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
                                return(-1);
                        }  
 
                        memcpy(file_acl_temp,file_acl,file_acl->acl_len);
-                       free(file_acl);
+                       SAFE_FREE(file_acl);
                        file_acl = file_acl_temp;
                }
 
@@ -1989,7 +1987,7 @@ int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl
        rc = chacl(name,file_acl,file_acl->acl_len);
        DEBUG(10,("errno is %d\n",errno));
        DEBUG(10,("return code is %d\n",rc));
-       free(file_acl);
+       SAFE_FREE(file_acl);
        DEBUG(10,("Exiting the sys_acl_set_file\n"));
        return(rc);
 }
@@ -2044,14 +2042,14 @@ int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
                        acl_length += sizeof(struct acl_entry);
                        file_acl_temp = (struct acl *)malloc(acl_length);
                        if(file_acl_temp == NULL) {
-                               free(file_acl);
+                               SAFE_FREE(file_acl);
                                errno = ENOMEM;
                                DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
                                return(-1);
                        }
 
                        memcpy(file_acl_temp,file_acl,file_acl->acl_len);
-                       free(file_acl);
+                       SAFE_FREE(file_acl);
                        file_acl = file_acl_temp;
                }
 
@@ -2078,7 +2076,7 @@ int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
        rc = fchacl(fd,file_acl,file_acl->acl_len);
        DEBUG(10,("errno is %d\n",errno));
        DEBUG(10,("return code is %d\n",rc));
-       free(file_acl);
+       SAFE_FREE(file_acl);
        DEBUG(10,("Exiting sys_acl_set_fd\n"));
        return(rc);
 }
@@ -2104,14 +2102,14 @@ int sys_acl_free_acl(SMB_ACL_T posix_acl)
        struct acl_entry_link *acl_entry_link;
 
        for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
-               free(acl_entry_link->prevp->entryp);
-               free(acl_entry_link->prevp);
+               SAFE_FREE(acl_entry_link->prevp->entryp);
+               SAFE_FREE(acl_entry_link->prevp);
        }
 
-       free(acl_entry_link->prevp->entryp);
-       free(acl_entry_link->prevp);
-       free(acl_entry_link->entryp);
-       free(acl_entry_link);
+       SAFE_FREE(acl_entry_link->prevp->entryp);
+       SAFE_FREE(acl_entry_link->prevp);
+       SAFE_FREE(acl_entry_link->entryp);
+       SAFE_FREE(acl_entry_link);
  
        return(0);
 }
index 185c1daa82d5659595ee4ce2e8594e6dc4260033..822aeb900444823bb6fe6082f5582c88df99b6be 100644 (file)
@@ -535,7 +535,7 @@ int sys_getgroups(int setlen, gid_t *gidset)
 
   if((ngroups = getgroups(setlen, group_list)) < 0) {
     int saved_errno = errno;
-    free((char *)group_list);
+    SAFE_FREE(group_list);
     errno = saved_errno;
     return -1;
   }
@@ -543,7 +543,7 @@ int sys_getgroups(int setlen, gid_t *gidset)
   for(i = 0; i < ngroups; i++)
     gidset[i] = (gid_t)group_list[i];
 
-  free((char *)group_list);
+  SAFE_FREE(group_list);
   return ngroups;
 #endif /* HAVE_BROKEN_GETGROUPS */
 }
@@ -587,12 +587,12 @@ int sys_setgroups(int setlen, gid_t *gidset)
 
   if(setgroups(setlen, group_list) != 0) {
     int saved_errno = errno;
-    free((char *)group_list);
+    SAFE_FREE(group_list);
     errno = saved_errno;
     return -1;
   }
  
-  free((char *)group_list);
+  SAFE_FREE(group_list);
   return 0 ;
 #endif /* HAVE_BROKEN_GETGROUPS */
 }
@@ -886,7 +886,7 @@ int sys_popen(const char *command)
         */
 
        close (child_end);
-       free((char *)argl);
+       SAFE_FREE(argl);
 
        /* Link into popen_chain. */
        entry->next = popen_chain;
@@ -897,10 +897,8 @@ int sys_popen(const char *command)
 
 err_exit:
 
-       if(entry)
-               free((char *)entry);
-       if(argl)
-               free((char *)argl);
+       SAFE_FREE(entry);
+       SAFE_FREE(argl);
        close(pipe_fds[0]);
        close(pipe_fds[1]);
        return -1;
@@ -940,7 +938,7 @@ int sys_pclose(int fd)
                wait_pid = sys_waitpid (entry->child_pid, &wstatus, 0);
        } while (wait_pid == -1 && errno == EINTR);
 
-       free((char *)entry);
+       SAFE_FREE(entry);
 
        if (wait_pid == -1)
                return -1;
index cfd130e888b0dcc9778f2eb0f22bf1860e10a06e..97ba196e2ac40f62b369dd38421c86808518c68a 100644 (file)
@@ -62,7 +62,7 @@ void *talloc(TALLOC_CTX *t, size_t size)
 
        tc = malloc(sizeof(*tc));
        if (!tc) {
-               free(p);
+               SAFE_FREE(p);
                return NULL;
        }
 
@@ -112,12 +112,11 @@ void talloc_destroy_pool(TALLOC_CTX *t)
 
        while (t->list) {
                c = t->list->next;
-               if (t->list->ptr) free(t->list->ptr);
-               free(t->list);
+               SAFE_FREE(t->list->ptr);
+               SAFE_FREE(t->list);
                t->list = c;
        }
 
-       t->list = NULL;
        t->total_alloc_size = 0;
 }
 
@@ -128,7 +127,7 @@ void talloc_destroy(TALLOC_CTX *t)
                return;
        talloc_destroy_pool(t);
        memset(t, 0, sizeof(*t));
-       free(t);
+       SAFE_FREE(t);
 }
 
 /* return the current total size of the pool. */
index 88be3fa334384261b85f3603afb73807070aa11a..f5cd96223c84f713fbaf53450f78062988db281b 100644 (file)
@@ -145,7 +145,7 @@ static int TimeZoneFaster(time_t t)
                                              sizeof(dst_table[0])*(i+1));
     if (!tdt) {
       DEBUG(0,("TimeZoneFaster: out of memory!\n"));
-      if (dst_table) free (dst_table);
+      SAFE_FREE(dst_table);
       table_size = 0;
     } else {
       dst_table = tdt;
index 9164fd3936a4a40bc9f70687b14b49152aee9f5b..2af477577eba8e5bac01cd69a408dc0fed398b42 100644 (file)
@@ -320,13 +320,13 @@ failed with error %s\n", strerror(errno) ));
        }
  
        *winbind_answered = True;
-       safe_free(groups);
+       SAFE_FREE(groups);
        return ret;
  
    err:
  
        *winbind_answered = False;
-       safe_free(groups);
+       SAFE_FREE(groups);
        return False;
 }            
  
index d1d052d4a029a7d7422f302bfd66003d44887c7e..3d2de63f3865e81f9fe28e7e14eb2703c9f1e874 100644 (file)
@@ -171,7 +171,7 @@ char *get_numlist(char *p, uint32 **num, int *count)
                tn = Realloc((*num), ((*count)+1) * sizeof(uint32));
                if (tn == NULL)
                {
-                       if (*num) free(*num);
+                       SAFE_FREE(*num);
                        return NULL;
                }
                else (*num) = tn;
@@ -638,7 +638,7 @@ void *Realloc(void *p,size_t size)
   void *ret=NULL;
 
   if (size == 0) {
-    if (p) free(p);
+    SAFE_FREE(p);
     DEBUG(5,("Realloc asked for 0 bytes\n"));
     return NULL;
   }
@@ -656,17 +656,15 @@ void *Realloc(void *p,size_t size)
 
 
 /****************************************************************************
-free memory, checks for NULL
+free memory, checks for NULL and set to NULL
+use directly SAFE_FREE()
+exist only because we need to pass a function pointer somewhere --SSS
 ****************************************************************************/
 void safe_free(void *p)
 {
-       if (p != NULL)
-       {
-               free(p);
-       }
+       SAFE_FREE(p);
 }
 
-
 /****************************************************************************
 get my own name and IP
 ****************************************************************************/
@@ -1243,13 +1241,11 @@ routine to free a namearray.
 
 void free_namearray(name_compare_entry *name_array)
 {
-  if(name_array == 0)
+  if(name_array == NULL)
     return;
 
-  if(name_array->name != NULL)
-    free(name_array->name);
-
-  free((char *)name_array);
+  SAFE_FREE(name_array->name);
+  SAFE_FREE(name_array);
 }
 
 /****************************************************************************
@@ -1498,7 +1494,7 @@ zero a memory area then free it. Used to catch bugs faster
 void zero_free(void *p, size_t size)
 {
        memset(p, 0, size);
-       free(p);
+       SAFE_FREE(p);
 }
 
 
index 8ad8da61c31e410261ea0158d9697e1daeb857e7..3e3a0cf3e32518d2073e3fbd32a0e02df645cef8 100644 (file)
@@ -35,7 +35,7 @@ void free_void_array(uint32 num_entries, void **entries,
                                free_item(entries[i]);
                        }
                }
-               free(entries);
+               SAFE_FREE(entries);
        }
 }
 
@@ -71,7 +71,7 @@ void* add_item_to_array(uint32 *len, void ***array, void *item)
                (*len)++;
                return item;
        } else {
-               free((char *)*array);
+               SAFE_FREE(*array);
        }
        return NULL;
 }
@@ -80,19 +80,10 @@ static void use_info_free(struct use_info *item)
 {
        if (item != NULL)
        {
-               if (item->srv_name != NULL)
-               {
-                       free(item->srv_name);
-               }
-               if (item->user_name != NULL)
-               {
-                       free(item->user_name);
-               }
-               if (item->domain != NULL)
-               {
-                       free(item->domain);
-               }
-               free(item);
+               SAFE_FREE(item->srv_name);
+               SAFE_FREE(item->user_name);
+               SAFE_FREE(item->domain);
+               SAFE_FREE(item);
        }
 }
 
@@ -141,7 +132,7 @@ struct use_info* add_use_info_to_array(uint32 *len, struct use_info ***array,
 
 void free_char_array(uint32 num_entries, char **entries)
 {
-       void(*fn)(void*) = (void(*)(void*))&free;
+       void(*fn)(void*) = (void(*)(void*))&safe_free;
        free_void_array(num_entries, (void**)entries, *fn);
 }
 
@@ -169,7 +160,7 @@ static uint32 *uint32_dup(const uint32* from)
 
 void free_uint32_array(uint32 num_entries, uint32 **entries)
 {
-       void(*fn)(void*) = (void(*)(void*))&free;
+       void(*fn)(void*) = (void(*)(void*))&safe_free;
        free_void_array(num_entries, (void**)entries, *fn);
 }
 
@@ -183,7 +174,7 @@ uint32* add_uint32s_to_array(uint32 *len, uint32 ***array, const uint32 *name)
 
 void free_sid_array(uint32 num_entries, DOM_SID **entries)
 {
-       void(*fn)(void*) = (void(*)(void*))&free;
+       void(*fn)(void*) = (void(*)(void*))&safe_free;
        free_void_array(num_entries, (void**)entries, *fn);
 }
 
index 8eeb3475e38fbfb6df5a86ef426a42561abe202e..35b47a2cbb3aadb4acbfa2fae538eb3be9f61136 100644 (file)
@@ -315,7 +315,7 @@ char *fgets_slash(char *s2,int maxlen,XFILE *f)
          return(s);
        case EOF:
          if (len <= 0 && !s2) 
-           free(s);
+           SAFE_FREE(s);
          return(len>0?s:NULL);
        case ' ':
          if (start_of_line)
@@ -333,7 +333,7 @@ char *fgets_slash(char *s2,int maxlen,XFILE *f)
          t = (char *)Realloc(s,maxlen);
          if (!t) {
            DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
-           if (s) free(s);
+           SAFE_FREE(s);
            return(NULL);
          } else s = t;
        }
@@ -363,7 +363,7 @@ char *file_pload(char *syscmd, size_t *size)
                if (!tp) {
                        DEBUG(0,("file_pload: failed to exand buffer!\n"));
                        close(fd);
-                       if (p) free(p);
+                       SAFE_FREE(p);
                        return NULL;
                } else p = tp;
                memcpy(p+total, buf, n);
@@ -393,7 +393,7 @@ char *fd_load(int fd, size_t *size)
        if (!p) return NULL;
 
        if (read(fd, p, sbuf.st_size) != sbuf.st_size) {
-               free(p);
+               SAFE_FREE(p);
                return NULL;
        }
        p[sbuf.st_size] = 0;
@@ -440,7 +440,7 @@ static char **file_lines_parse(char *p, size_t size, int *numlines)
 
        ret = (char **)malloc(sizeof(ret[0])*(i+2));
        if (!ret) {
-               free(p);
+               SAFE_FREE(p);
                return NULL;
        }       
        memset(ret, 0, sizeof(ret[0])*(i+2));
@@ -513,8 +513,8 @@ free lines loaded with file_lines_load
 void file_lines_free(char **lines)
 {
        if (!lines) return;
-       free(lines[0]);
-       free(lines);
+       SAFE_FREE(lines[0]);
+       SAFE_FREE(lines);
 }
 
 
index 5c1652f6bf518c1f44b79113077efdbd18643300..4393debabaec3bbe82eb82dc38267c82006527e5 100644 (file)
@@ -66,7 +66,7 @@ struct sys_grent * getgrent_list(void)
        grp = getgrent();
        if (grp == NULL) {
                endgrent();
-               free(glist);
+               SAFE_FREE(glist);
                return NULL;
        }
 
@@ -130,19 +130,17 @@ void grent_free (struct sys_grent *glist)
        while (glist) {
                struct sys_grent *prev;
                
-               if (glist->gr_name)
-                       free(glist->gr_name);
-               if (glist->gr_passwd)
-                       free(glist->gr_passwd);
+               SAFE_FREE(glist->gr_name);
+               SAFE_FREE(glist->gr_passwd);
                if (glist->gr_mem) {
                        int i;
                        for (i = 0; glist->gr_mem[i]; i++)
-                               free(glist->gr_mem[i]);
-                       free(glist->gr_mem);
+                               SAFE_FREE(glist->gr_mem[i]);
+                       SAFE_FREE(glist->gr_mem);
                }
                prev = glist;
                glist = glist->next;
-               free(prev);
+               SAFE_FREE(prev);
        }
 }
 
@@ -221,19 +219,14 @@ void pwent_free (struct sys_pwent *plist)
        while (plist) {
                struct sys_pwent *prev;
                
-               if (plist->pw_name)
-                       free(plist->pw_name);
-               if (plist->pw_passwd)
-                       free(plist->pw_passwd);
-               if (plist->pw_gecos)
-                       free(plist->pw_gecos);
-               if (plist->pw_dir)
-                       free(plist->pw_dir);
-               if (plist->pw_shell)
-                       free(plist->pw_shell);
+               SAFE_FREE(plist->pw_name);
+               SAFE_FREE(plist->pw_passwd);
+               SAFE_FREE(plist->pw_gecos);
+               SAFE_FREE(plist->pw_dir);
+               SAFE_FREE(plist->pw_shell);
 
                prev = plist;
                plist = plist->next;
-               free(prev);
+               SAFE_FREE(prev);
        }
 }
index 19354c878431ea45c1b8ac230bf62c64aee7948b..5fe2914a92b9760d99bf37aefa18912b4b53fe01 100644 (file)
@@ -174,7 +174,7 @@ static void* generic_list_locate (GENERIC_LIST *l, void *search,
 
                        l->length--;
                        data_ptr = item->data;
-                       free(item);
+                       SAFE_FREE(item);
                        return data_ptr;
                }
                /* increment to the nbext node in the list */
@@ -291,7 +291,7 @@ BOOL RpcHndList_del_connection(const POLICY_HND *hnd)
 
        /* delete the information */
        cli_connection_free(located->cli);
-       free(located);
+       SAFE_FREE(located);
        return True;
 }
 
index 565703a8000937efdf3500542a864d3c90365685..8518d75a49b55869f45b737b4ae7ef186f1186e3 100644 (file)
@@ -632,8 +632,7 @@ void string_free(char **s)
   if (!s || !(*s)) return;
   if (*s == null_string)
     *s = NULL;
-  if (*s) free(*s);
-  *s = NULL;
+  SAFE_FREE(*s);
 }
 
 /****************************************************************************
index e6c0c516083685b18b8d4af687cdd66e5cf6060b..5a9b065008e661294f1c0a267cecdd412b5e0a6a 100644 (file)
@@ -131,9 +131,8 @@ BOOL wins_srv_load_list( char *src )
   /* Empty the list. */
   while( NULL != (entry =(list_entry *)ubi_slRemHead( wins_srv_list )) )
     {
-    if( entry->server )
-      free( entry->server );
-    free( entry );
+    SAFE_FREE( entry->server );
+    SAFE_FREE( entry );
     }
   (void)ubi_slInitList( wins_srv_list );  /* shouldn't be needed */
 
@@ -152,7 +151,7 @@ BOOL wins_srv_load_list( char *src )
       /* Create a copy of the server name and store it in the list. */
       if( NULL == (entry->server = strdup( wins_id_bufr )) )
         {
-        free( entry );
+        SAFE_FREE( entry );
         DEBUG( 0,
           ("wins_srv_load_list(): strdup(\"%s\") failed.\n", wins_id_bufr) );
         }
index 3a86d2469d0320de347efd3d86bf0c5292e62c01..6e21aeca58fbe154bfbfdf4107f9f3edd65da967 100644 (file)
@@ -57,7 +57,7 @@ int x_setvbuf(XFILE *f, char *buf, int mode, size_t size)
        }
 
        /* destroy any earlier buffer */
-       if (f->buf) free(f->buf);
+       SAFE_FREE(f->buf);
        f->buf = 0;
        f->bufsize = 0;
        f->next = NULL;
@@ -111,7 +111,7 @@ XFILE *x_fopen(const char *fname, int flags, mode_t mode)
 
        ret->fd = sys_open(fname, flags, mode);
        if (ret->fd == -1) {
-               free(ret);
+               SAFE_FREE(ret);
                return NULL;
        }
 
@@ -133,9 +133,9 @@ int x_fclose(XFILE *f)
        if (f->buf) {
                /* make sure data can't leak into a later malloc */
                memset(f->buf, 0, f->bufsize);
-               free(f->buf);
+               SAFE_FREE(f->buf);
        }
-       free(f);
+       SAFE_FREE(f);
        return ret;
 }
 
@@ -191,7 +191,7 @@ int x_vfprintf(XFILE *f, const char *format, va_list ap)
        len = vasprintf(&p, format, ap);
        if (len <= 0) return len;
        ret = x_fwrite(p, 1, len, f);
-       free(p);
+       SAFE_FREE(p);
        return ret;
 }