summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2001-09-17 02:19:44 +0000
committerSimo Sorce <idra@samba.org>2001-09-17 02:19:44 +0000
commit484a7c0341fe033fe26fe1e6b597ed1c456c39d4 (patch)
treec2f2344c757fffba5b6cc190e6ed13ef64b89266
parent31c3f7a8b2ff62d4cfc1ed9d831b95eba0da525f (diff)
downloadsamba-484a7c0341fe033fe26fe1e6b597ed1c456c39d4.tar.gz
samba-484a7c0341fe033fe26fe1e6b597ed1c456c39d4.tar.bz2
samba-484a7c0341fe033fe26fe1e6b597ed1c456c39d4.zip
move to SAFE_FREE()
(This used to be commit 60e907b7e8e1c008463a88ed2b076344278986ef)
-rw-r--r--source3/lib/access.c2
-rw-r--r--source3/lib/bitmap.c8
-rw-r--r--source3/lib/cmd_interp.c6
-rw-r--r--source3/lib/dprintf.c8
-rw-r--r--source3/lib/genrand.c3
-rw-r--r--source3/lib/hash.c22
-rw-r--r--source3/lib/iconv.c4
-rw-r--r--source3/lib/interface.c7
-rw-r--r--source3/lib/messages.c14
-rw-r--r--source3/lib/replace.c2
-rw-r--r--source3/lib/sysacls.c68
-rw-r--r--source3/lib/system.c18
-rw-r--r--source3/lib/talloc.c9
-rw-r--r--source3/lib/time.c2
-rw-r--r--source3/lib/username.c4
-rw-r--r--source3/lib/util.c24
-rw-r--r--source3/lib/util_array.c27
-rw-r--r--source3/lib/util_file.c14
-rw-r--r--source3/lib/util_getent.c31
-rw-r--r--source3/lib/util_list.c4
-rw-r--r--source3/lib/util_str.c3
-rw-r--r--source3/lib/wins_srv.c7
-rw-r--r--source3/lib/xfile.c10
23 files changed, 129 insertions, 168 deletions
diff --git a/source3/lib/access.c b/source3/lib/access.c
index 99f3cc49b5..b3d1838484 100644
--- a/source3/lib/access.c
+++ b/source3/lib/access.c
@@ -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
diff --git a/source3/lib/bitmap.c b/source3/lib/bitmap.c
index 7625f52909..2ae9defb2d 100644
--- a/source3/lib/bitmap.c
+++ b/source3/lib/bitmap.c
@@ -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);
}
/****************************************************************************
diff --git a/source3/lib/cmd_interp.c b/source3/lib/cmd_interp.c
index 62e361408b..5ebb8a94d2 100644
--- a/source3/lib/cmd_interp.c
+++ b/source3/lib/cmd_interp.c
@@ -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 */
diff --git a/source3/lib/dprintf.c b/source3/lib/dprintf.c
index 157ce6b716..964d63c72f 100644
--- a/source3/lib/dprintf.c
+++ b/source3/lib/dprintf.c
@@ -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;
}
diff --git a/source3/lib/genrand.c b/source3/lib/genrand.c
index d5556149af..c4fb925a75 100644
--- a/source3/lib/genrand.c
+++ b/source3/lib/genrand.c
@@ -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);
diff --git a/source3/lib/hash.c b/source3/lib/hash.c
index 92840a4c98..6c81931152 100644
--- a/source3/lib/hash.c
+++ b/source3/lib/hash.c
@@ -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;
}
diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c
index 46507dd624..a8962726e0 100644
--- a/source3/lib/iconv.c
+++ b/source3/lib/iconv.c
@@ -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;
}
diff --git a/source3/lib/interface.c b/source3/lib/interface.c
index c89c22aa08..c68b405f7c 100644
--- a/source3/lib/interface.c
+++ b/source3/lib/interface.c
@@ -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 */
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 18f9d0c1d5..5e7072c2b4 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -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);
}
}
}
diff --git a/source3/lib/replace.c b/source3/lib/replace.c
index 45c302f498..e1871a6f55 100644
--- a/source3/lib/replace.c
+++ b/source3/lib/replace.c
@@ -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 */
}
diff --git a/source3/lib/sysacls.c b/source3/lib/sysacls.c
index 424e705755..1c840d84ca 100644
--- a/source3/lib/sysacls.c
+++ b/source3/lib/sysacls.c
@@ -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);
}
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 185c1daa82..822aeb9004 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -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;
diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c
index cfd130e888..97ba196e2a 100644
--- a/source3/lib/talloc.c
+++ b/source3/lib/talloc.c
@@ -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. */
diff --git a/source3/lib/time.c b/source3/lib/time.c
index 88be3fa334..f5cd96223c 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -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;
diff --git a/source3/lib/username.c b/source3/lib/username.c
index 9164fd3936..2af477577e 100644
--- a/source3/lib/username.c
+++ b/source3/lib/username.c
@@ -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;
}
diff --git a/source3/lib/util.c b/source3/lib/util.c
index d1d052d4a0..3d2de63f38 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -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);
}
diff --git a/source3/lib/util_array.c b/source3/lib/util_array.c
index 8ad8da61c3..3e3a0cf3e3 100644
--- a/source3/lib/util_array.c
+++ b/source3/lib/util_array.c
@@ -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);
}
diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c
index 8eeb3475e3..35b47a2cbb 100644
--- a/source3/lib/util_file.c
+++ b/source3/lib/util_file.c
@@ -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);
}
diff --git a/source3/lib/util_getent.c b/source3/lib/util_getent.c
index 5c1652f6bf..4393debaba 100644
--- a/source3/lib/util_getent.c
+++ b/source3/lib/util_getent.c
@@ -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);
}
}
diff --git a/source3/lib/util_list.c b/source3/lib/util_list.c
index 19354c8784..5fe2914a92 100644
--- a/source3/lib/util_list.c
+++ b/source3/lib/util_list.c
@@ -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;
}
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 565703a800..8518d75a49 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -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);
}
/****************************************************************************
diff --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c
index e6c0c51608..5a9b065008 100644
--- a/source3/lib/wins_srv.c
+++ b/source3/lib/wins_srv.c
@@ -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) );
}
diff --git a/source3/lib/xfile.c b/source3/lib/xfile.c
index 3a86d2469d..6e21aeca58 100644
--- a/source3/lib/xfile.c
+++ b/source3/lib/xfile.c
@@ -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;
}