summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2001-09-17 11:25:41 +0000
committerSimo Sorce <idra@samba.org>2001-09-17 11:25:41 +0000
commit61b2794968faa35dc91edce17e9b91e5366c3514 (patch)
tree3fd9ec24adcdf149263066754f5e51ac7a4e14e0
parent87945989c0383bd012be7ab8bc5920b6d03fa105 (diff)
downloadsamba-61b2794968faa35dc91edce17e9b91e5366c3514.tar.gz
samba-61b2794968faa35dc91edce17e9b91e5366c3514.tar.bz2
samba-61b2794968faa35dc91edce17e9b91e5366c3514.zip
move to SAFE_FREE()
(This used to be commit a95943fde0ad89ae3f2deca2f7ba9cb5ab612b74)
-rw-r--r--source3/auth/auth_sam.c4
-rw-r--r--source3/auth/auth_server.c2
-rw-r--r--source3/smbd/auth_server.c2
-rw-r--r--source3/smbd/auth_smbpasswd.c4
-rw-r--r--source3/smbd/blocking.c6
-rw-r--r--source3/smbd/close.c2
-rw-r--r--source3/smbd/conn.c5
-rw-r--r--source3/smbd/dir.c22
-rw-r--r--source3/smbd/fileio.c8
-rw-r--r--source3/smbd/files.c2
-rw-r--r--source3/smbd/groupname.c16
-rw-r--r--source3/smbd/ipc.c22
-rw-r--r--source3/smbd/lanman.c32
-rw-r--r--source3/smbd/mangle.c8
-rw-r--r--source3/smbd/notify.c4
-rw-r--r--source3/smbd/notify_hash.c2
-rw-r--r--source3/smbd/notify_kernel.c2
-rw-r--r--source3/smbd/nttrans.c33
-rw-r--r--source3/smbd/open.c17
-rw-r--r--source3/smbd/oplock.c10
-rw-r--r--source3/smbd/password.c8
-rw-r--r--source3/smbd/posix_acls.c20
-rw-r--r--source3/smbd/process.c6
-rw-r--r--source3/smbd/quotas.c2
-rw-r--r--source3/smbd/reply.c2
-rw-r--r--source3/smbd/sec_ctx.c16
-rw-r--r--source3/smbd/session.c3
-rw-r--r--source3/smbd/trans2.c24
-rw-r--r--source3/smbd/vfs.c2
-rw-r--r--source3/smbwrapper/smbw.c30
-rw-r--r--source3/smbwrapper/smbw_cache.c6
-rw-r--r--source3/smbwrapper/smbw_dir.c16
32 files changed, 145 insertions, 193 deletions
diff --git a/source3/auth/auth_sam.c b/source3/auth/auth_sam.c
index b61fde4206..fb77a7a5c6 100644
--- a/source3/auth/auth_sam.c
+++ b/source3/auth/auth_sam.c
@@ -151,11 +151,11 @@ NTSTATUS smb_password_ok(SAM_ACCOUNT *sampass, const auth_usersupplied_info *use
}
}
- free(workstation_list);
+ SAFE_FREE(workstation_list);
if (invalid_ws)
return NT_STATUS_INVALID_WORKSTATION;
} else {
- free(workstation_list);
+ SAFE_FREE(workstation_list);
}
} else {
return NT_STATUS_NO_MEMORY;
diff --git a/source3/auth/auth_server.c b/source3/auth/auth_server.c
index 7ed4cf60ad..e4c91c4dcb 100644
--- a/source3/auth/auth_server.c
+++ b/source3/auth/auth_server.c
@@ -77,7 +77,7 @@ struct cli_state *server_cryptkey(void)
}
}
- free(pserver);
+ SAFE_FREE(pserver);
if (!connected_ok) {
DEBUG(0,("password server not available\n"));
diff --git a/source3/smbd/auth_server.c b/source3/smbd/auth_server.c
index 7ed4cf60ad..e4c91c4dcb 100644
--- a/source3/smbd/auth_server.c
+++ b/source3/smbd/auth_server.c
@@ -77,7 +77,7 @@ struct cli_state *server_cryptkey(void)
}
}
- free(pserver);
+ SAFE_FREE(pserver);
if (!connected_ok) {
DEBUG(0,("password server not available\n"));
diff --git a/source3/smbd/auth_smbpasswd.c b/source3/smbd/auth_smbpasswd.c
index b61fde4206..fb77a7a5c6 100644
--- a/source3/smbd/auth_smbpasswd.c
+++ b/source3/smbd/auth_smbpasswd.c
@@ -151,11 +151,11 @@ NTSTATUS smb_password_ok(SAM_ACCOUNT *sampass, const auth_usersupplied_info *use
}
}
- free(workstation_list);
+ SAFE_FREE(workstation_list);
if (invalid_ws)
return NT_STATUS_INVALID_WORKSTATION;
} else {
- free(workstation_list);
+ SAFE_FREE(workstation_list);
}
} else {
return NT_STATUS_NO_MEMORY;
diff --git a/source3/smbd/blocking.c b/source3/smbd/blocking.c
index 2008598104..cec1581254 100644
--- a/source3/smbd/blocking.c
+++ b/source3/smbd/blocking.c
@@ -46,8 +46,8 @@ static ubi_slList blocking_lock_queue = { NULL, (ubi_slNodePtr)&blocking_lock_qu
static void free_blocking_lock_record(blocking_lock_record *blr)
{
- free(blr->inbuf);
- free((char *)blr);
+ SAFE_FREE(blr->inbuf);
+ SAFE_FREE(blr);
}
/****************************************************************************
@@ -103,7 +103,7 @@ BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout, int
if((blr->inbuf = (char *)malloc(length)) == NULL) {
DEBUG(0,("push_blocking_lock_request: Malloc fail (2)!\n" ));
- free((char *)blr);
+ SAFE_FREE(blr);
return False;
}
diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index f790778676..c92e084759 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -161,7 +161,7 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close)
GET_DELETE_ON_CLOSE_FLAG(share_entry->share_mode) )
delete_on_close = True;
- safe_free(share_entry);
+ SAFE_FREE(share_entry);
/*
* NT can set delete_on_close of the last open
diff --git a/source3/smbd/conn.c b/source3/smbd/conn.c
index c2faa4f15a..08704927c5 100644
--- a/source3/smbd/conn.c
+++ b/source3/smbd/conn.c
@@ -177,8 +177,7 @@ void conn_free(connection_struct *conn)
DLIST_REMOVE(Connections, conn);
if (conn->ngroups && conn->groups) {
- free(conn->groups);
- conn->groups = NULL;
+ SAFE_FREE(conn->groups);
conn->ngroups = 0;
}
@@ -196,7 +195,7 @@ void conn_free(connection_struct *conn)
num_open--;
ZERO_STRUCTP(conn);
- free(conn);
+ SAFE_FREE(conn);
}
diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index 9a9c745944..c0c728fe8f 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -246,10 +246,9 @@ static void dptr_close_internal(dptr_struct *dptr)
}
/* Lanman 2 specific code */
- if (dptr->wcard)
- free(dptr->wcard);
+ SAFE_FREE(dptr->wcard);
string_set(&dptr->path,"");
- free((char *)dptr);
+ SAFE_FREE(dptr);
}
/****************************************************************************
@@ -438,7 +437,7 @@ int dptr_create(connection_struct *conn,char *path, BOOL old_handle, BOOL expect
if(dptr->dnum == -1 || dptr->dnum > 254) {
DEBUG(0,("dptr_create: returned %d: Error - all old dirptrs in use ?\n", dptr->dnum));
- free((char *)dptr);
+ SAFE_FREE(dptr);
return -1;
}
}
@@ -467,7 +466,7 @@ int dptr_create(connection_struct *conn,char *path, BOOL old_handle, BOOL expect
if(dptr->dnum == -1 || dptr->dnum < 255) {
DEBUG(0,("dptr_create: returned %d: Error - all new dirptrs in use ?\n", dptr->dnum));
- free((char *)dptr);
+ SAFE_FREE(dptr);
return -1;
}
}
@@ -730,7 +729,7 @@ void *OpenDir(connection_struct *conn, char *name, BOOL use_veto)
if (asprintf(&entry, "%s/%s/%s", conn->origpath, name, n) > 0) {
ret = user_can_read_file(conn, entry);
- free(entry);
+ SAFE_FREE(entry);
}
if (!ret) continue;
}
@@ -763,10 +762,9 @@ void *OpenDir(connection_struct *conn, char *name, BOOL use_veto)
void CloseDir(void *p)
{
- Dir *dirp = (Dir *)p;
- if (!dirp) return;
- if (dirp->data) free(dirp->data);
- free(dirp);
+ if (!p) return;
+ SAFE_FREE(((Dir *)p)->data);
+ SAFE_FREE(p);
}
/*******************************************************************
@@ -875,7 +873,7 @@ void DirCacheAdd( char *path, char *name, char *dname, int snum )
/* Free excess cache entries. */
while( DIRCACHESIZE < dir_cache->count )
- free( ubi_dlRemTail( dir_cache ) );
+ safe_free( ubi_dlRemTail( dir_cache ) );
}
@@ -927,7 +925,7 @@ void DirCacheFlush(int snum)
NULL != entry; ) {
next = ubi_dlNext( entry );
if( entry->snum == snum )
- free( ubi_dlRemThis( dir_cache, entry ) );
+ safe_free( ubi_dlRemThis( dir_cache, entry ) );
entry = (dir_cache_entry *)next;
}
}
diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index c79f0aa89e..003bee84ed 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -482,10 +482,8 @@ void delete_write_cache(files_struct *fsp)
SMB_ASSERT(wcp->data_size == 0);
- free(wcp->data);
- free(wcp);
-
- fsp->wcp = NULL;
+ SAFE_FREE(wcp->data);
+ SAFE_FREE(fsp->wcp);
DEBUG(10,("delete_write_cache: File %s deleted write cache\n", fsp->fsp_name ));
@@ -518,7 +516,7 @@ static BOOL setup_write_cache(files_struct *fsp, SMB_OFF_T file_size)
if((wcp->data = malloc(wcp->alloc_size)) == NULL) {
DEBUG(0,("setup_write_cache: malloc fail for buffer size %u.\n",
(unsigned int)wcp->alloc_size ));
- free(wcp);
+ SAFE_FREE(wcp);
return False;
}
diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index 27dfad7c48..4273c205cd 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -311,7 +311,7 @@ void file_free(files_struct *fsp)
if (fsp == chain_fsp) chain_fsp = NULL;
- free(fsp);
+ SAFE_FREE(fsp);
}
diff --git a/source3/smbd/groupname.c b/source3/smbd/groupname.c
index 0640d4d7b2..eb2931d2a5 100644
--- a/source3/smbd/groupname.c
+++ b/source3/smbd/groupname.c
@@ -53,11 +53,9 @@ static void delete_groupname_map_list(void)
groupname_map_entry *gmep;
while((gmep = (groupname_map_entry *)ubi_slRemHead( &groupname_map_list )) != NULL) {
- if(gmep->windows_name)
- free(gmep->windows_name);
- if(gmep->unix_name)
- free(gmep->unix_name);
- free((char *)gmep);
+ SAFE_FREE(gmep->windows_name);
+ SAFE_FREE(gmep->unix_name);
+ SAFE_FREE(gmep);
}
}
@@ -188,11 +186,9 @@ Error was %s.\n", unixname, strerror(errno) ));
if(new_ep->windows_name == NULL || new_ep->unix_name == NULL) {
DEBUG(0,("load_groupname_map: malloc fail for names in groupname_map_entry.\n"));
fclose(fp);
- if(new_ep->windows_name != NULL)
- free(new_ep->windows_name);
- if(new_ep->unix_name != NULL)
- free(new_ep->unix_name);
- free((char *)new_ep);
+ SAFE_FREE(new_ep->windows_name);
+ SAFE_FREE(new_ep->unix_name);
+ SAFE_FREE(new_ep);
file_lines_free(lines);
return;
}
diff --git a/source3/smbd/ipc.c b/source3/smbd/ipc.c
index a323261d88..b1af01ff4c 100644
--- a/source3/smbd/ipc.c
+++ b/source3/smbd/ipc.c
@@ -175,13 +175,13 @@ static BOOL api_rpc_trans_reply(char *outbuf, pipes_struct *p)
}
if((data_len = read_from_pipe( p, rdata, p->max_trans_reply)) < 0) {
- free(rdata);
+ SAFE_FREE(rdata);
return False;
}
send_trans_reply(outbuf, NULL, 0, rdata, data_len, p->out_data.current_pdu_len > data_len);
- free(rdata);
+ SAFE_FREE(rdata);
return True;
}
@@ -434,12 +434,9 @@ int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int
DEBUG(0,("reply_trans: %s in getting secondary trans response.\n",
(smb_read_error == READ_ERROR) ? "error" : "timeout" ));
}
- if (params)
- free(params);
- if (data)
- free(data);
- if (setup)
- free(setup);
+ SAFE_FREE(params);
+ SAFE_FREE(data);
+ SAFE_FREE(setup);
END_PROFILE(SMBtrans);
return(ERROR_DOS(ERRSRV,ERRerror));
}
@@ -501,12 +498,9 @@ int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int
}
- if (data)
- free(data);
- if (params)
- free(params);
- if (setup)
- free(setup);
+ SAFE_FREE(data);
+ SAFE_FREE(params);
+ SAFE_FREE(setup);
if (close_on_completion)
close_cnum(conn,vuid);
diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c
index eb0e7154a2..4d3da88783 100644
--- a/source3/smbd/lanman.c
+++ b/source3/smbd/lanman.c
@@ -945,10 +945,8 @@ static BOOL api_DosPrintQGetInfo(connection_struct *conn,
DEBUG(4,("printqgetinfo: errorcode %d\n",desc.errcode));
- if (queue)
- free(queue);
- if (tmpdata)
- free (tmpdata);
+ SAFE_FREE(queue);
+ SAFE_FREE(tmpdata);
return(True);
}
@@ -1038,7 +1036,7 @@ static BOOL api_DosPrintQEnum(connection_struct *conn, uint16 vuid, char* param,
}
}
- if (subcntarr) free(subcntarr);
+ SAFE_FREE(subcntarr);
*rdata_len = desc.usedlen;
*rparam_len = 8;
@@ -1049,11 +1047,11 @@ static BOOL api_DosPrintQEnum(connection_struct *conn, uint16 vuid, char* param,
SSVAL(*rparam,6,queuecnt);
for (i = 0; i < queuecnt; i++) {
- if (queue && queue[i]) free(queue[i]);
+ if (queue) SAFE_FREE(queue[i]);
}
- if (queue) free(queue);
- if (status) free(status);
+ SAFE_FREE(queue);
+ SAFE_FREE(status);
return True;
}
@@ -1403,7 +1401,7 @@ static BOOL api_RNetServerEnum(connection_struct *conn, uint16 vuid, char *param
SSVAL(*rparam,4,counted);
SSVAL(*rparam,6,counted+missed);
- if (servers) free(servers);
+ SAFE_FREE(servers);
DEBUG(3,("NetServerEnum domain = %s uLevel=%d counted=%d total=%d\n",
domain,uLevel,counted,counted+missed));
@@ -2274,7 +2272,7 @@ static BOOL api_RNetServerGetInfo(connection_struct *conn,uint16 vuid, char *par
pstrcpy(comment,servers[i].comment);
}
}
- if (servers) free(servers);
+ SAFE_FREE(servers);
SCVAL(p,0,lp_major_announce_version());
SCVAL(p,1,lp_minor_announce_version());
@@ -2939,8 +2937,8 @@ static BOOL api_WPrintJobGetInfo(connection_struct *conn,uint16 vuid, char *para
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,desc.neededlen);
- if (queue) free(queue);
- if (tmpdata) free(tmpdata);
+ SAFE_FREE(queue);
+ SAFE_FREE(tmpdata);
DEBUG(4,("WPrintJobGetInfo: errorcode %d\n",desc.errcode));
return(True);
@@ -3009,7 +3007,7 @@ static BOOL api_WPrintJobEnumerate(connection_struct *conn,uint16 vuid, char *pa
SSVAL(*rparam,4,succnt);
SSVAL(*rparam,6,count);
- if (queue) free(queue);
+ SAFE_FREE(queue);
DEBUG(4,("WPrintJobEnumerate: errorcode %d\n",desc.errcode));
return(True);
@@ -3128,7 +3126,7 @@ static BOOL api_WPrintDestGetInfo(connection_struct *conn,uint16 vuid, char *par
SSVAL(*rparam,4,desc.neededlen);
DEBUG(4,("WPrintDestGetInfo: errorcode %d\n",desc.errcode));
- if (tmpdata) free (tmpdata);
+ SAFE_FREE(tmpdata);
return(True);
}
@@ -3478,10 +3476,8 @@ int api_reply(connection_struct *conn,uint16 vuid,char *outbuf,char *data,char *
send_trans_reply(outbuf, rparam, rparam_len, rdata, rdata_len, False);
- if (rdata )
- free(rdata);
- if (rparam)
- free(rparam);
+ SAFE_FREE(rdata);
+ SAFE_FREE(rparam);
return -1;
}
diff --git a/source3/smbd/mangle.c b/source3/smbd/mangle.c
index 16286a8bb1..0e6689d9d2 100644
--- a/source3/smbd/mangle.c
+++ b/source3/smbd/mangle.c
@@ -451,7 +451,7 @@ static signed int cache_compare( ubi_btItemPtr ItemPtr, ubi_btNodePtr NodePtr )
static void cache_free_entry( ubi_trNodePtr WarrenZevon )
{
ZERO_STRUCTP(WarrenZevon);
- free( WarrenZevon );
+ SAFE_FREE( WarrenZevon );
} /* cache_free_entry */
/* ************************************************************************** **
@@ -618,7 +618,7 @@ BOOL check_mangled_cache( char *s )
{
/* Replace the saved_ext as it was truncated. */
(void)pstrcat( s, saved_ext );
- free(saved_ext);
+ SAFE_FREE(saved_ext);
}
return( False );
}
@@ -634,7 +634,7 @@ BOOL check_mangled_cache( char *s )
{
/* Replace the saved_ext as it was truncated. */
(void)pstrcat( s, saved_ext );
- free(saved_ext);
+ SAFE_FREE(saved_ext);
}
DEBUG( 3, ("as %s\n", s) );
@@ -957,7 +957,7 @@ BOOL name_map_mangle(char *OutName, BOOL need83, BOOL cache83, int snum)
if(tmp != NULL) {
cache_mangled_name(OutName, tmp);
- free(tmp);
+ SAFE_FREE(tmp);
}
}
diff --git a/source3/smbd/notify.c b/source3/smbd/notify.c
index 5aa0b4ad3f..68b51aeabb 100644
--- a/source3/smbd/notify.c
+++ b/source3/smbd/notify.c
@@ -76,7 +76,7 @@ static void change_notify_remove(struct change_notify *cnbp)
cnotify->remove_notify(cnbp->change_data);
DLIST_REMOVE(change_notify_list, cnbp);
ZERO_STRUCTP(cnbp);
- free(cnbp);
+ SAFE_FREE(cnbp);
}
@@ -188,7 +188,7 @@ BOOL change_notify_set(char *inbuf, files_struct *fsp, connection_struct *conn,
cnbp->change_data = cnotify->register_notify(conn, fsp->fsp_name, flags);
if (!cnbp->change_data) {
- free(cnbp);
+ SAFE_FREE(cnbp);
return False;
}
diff --git a/source3/smbd/notify_hash.c b/source3/smbd/notify_hash.c
index a0a61569a8..8157e1ff31 100644
--- a/source3/smbd/notify_hash.c
+++ b/source3/smbd/notify_hash.c
@@ -164,7 +164,7 @@ remove a change notify data structure
*****************************************************************************/
static void hash_remove_notify(void *datap)
{
- free(datap);
+ SAFE_FREE(datap);
}
diff --git a/source3/smbd/notify_kernel.c b/source3/smbd/notify_kernel.c
index 11a5592458..4b84831550 100644
--- a/source3/smbd/notify_kernel.c
+++ b/source3/smbd/notify_kernel.c
@@ -111,7 +111,7 @@ static void kernel_remove_notify(void *datap)
}
close(fd);
}
- free(data);
+ SAFE_FREE(data);
DEBUG(3,("removed kernel change notify fd=%d\n", fd));
}
diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index ca1efd0221..c072a38474 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -1693,9 +1693,9 @@ due to being in oplock break state.\n" ));
if ((total_parameter_count && !params) || (total_data_count && !data) ||
(setup_count && !setup)) {
- safe_free(setup);
- safe_free(params);
- safe_free(data);
+ SAFE_FREE(setup);
+ SAFE_FREE(params);
+ SAFE_FREE(data);
DEBUG(0,("reply_nttrans : Out of memory\n"));
END_PROFILE(SMBnttrans);
return ERROR_DOS(ERRDOS,ERRnomem);
@@ -1745,12 +1745,9 @@ due to being in oplock break state.\n" ));
DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
(smb_read_error == READ_ERROR) ? "error" : "timeout" ));
}
- if(params)
- free(params);
- if(data)
- free(data);
- if(setup)
- free(setup);
+ SAFE_FREE(params);
+ SAFE_FREE(data);
+ SAFE_FREE(setup);
END_PROFILE(SMBnttrans);
return ERROR_DOS(ERRSRV,ERRerror);
}
@@ -1821,12 +1818,9 @@ due to being in oplock break state.\n" ));
default:
/* Error in request */
DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code));
- if(setup)
- free(setup);
- if(params)
- free(params);
- if(data)
- free(data);
+ SAFE_FREE(setup);
+ SAFE_FREE(params);
+ SAFE_FREE(data);
END_PROFILE(SMBnttrans);
return ERROR_DOS(ERRSRV,ERRerror);
}
@@ -1838,12 +1832,9 @@ due to being in oplock break state.\n" ));
an error packet.
*/
- if(setup)
- free(setup);
- if(params)
- free(params);
- if(data)
- free(data);
+ SAFE_FREE(setup);
+ SAFE_FREE(params);
+ SAFE_FREE(data);
END_PROFILE(SMBnttrans);
return outsize; /* If a correct response was needed the call_nt_transact_xxxx
calls have already sent it. If outsize != -1 then it is
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 7974ea0ae0..7ac5a18609 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -499,7 +499,7 @@ dev = %x, inode = %.0f\n", *p_oplock_request, share_entry->op_type, fname, (unsi
if(opb_ret == False) {
DEBUG(0,("open_mode_check: FAILED when breaking oplock (%x) on file %s, \
dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (double)inode));
- free((char *)old_shares);
+ SAFE_FREE(old_shares);
errno = EACCES;
unix_ERR_class = ERRDOS;
unix_ERR_code = ERRbadshare;
@@ -518,7 +518,7 @@ dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (dou
if we can too */
if(check_share_mode(share_entry, share_mode, fname, fcbopen, p_flags) == False) {
- free((char *)old_shares);
+ SAFE_FREE(old_shares);
errno = EACCES;
return -1;
}
@@ -526,7 +526,7 @@ dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (dou
} /* end for */
if(broke_oplock) {
- free((char *)old_shares);
+ SAFE_FREE(old_shares);
num_share_modes = get_share_modes(conn, dev, inode, &old_shares);
oplock_contention_count++;
@@ -565,7 +565,7 @@ dev = %x, inode = %.0f. Deleting it to continue...\n", (int)broken_entry.pid, fn
* other process's entry.
*/
- free((char *)old_shares);
+ SAFE_FREE(old_shares);
num_share_modes = get_share_modes(conn, dev, inode, &old_shares);
break;
}
@@ -575,7 +575,7 @@ dev = %x, inode = %.0f. Deleting it to continue...\n", (int)broken_entry.pid, fn
} while(broke_oplock);
if(old_shares != 0)
- free((char *)old_shares);
+ SAFE_FREE(old_shares);
/*
* Refuse to grant an oplock in case the contention limit is
@@ -1237,7 +1237,7 @@ dev = %x, inode = %.0f\n", share_entry->op_type, fname, (unsigned int)dev, (doub
DEBUG(0,("check_file_sharing: FAILED when breaking oplock (%x) on file %s, \
dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (double)inode));
- free((char *)old_shares);
+ SAFE_FREE(old_shares);
return False;
}
lock_share_entry(conn, dev, inode);
@@ -1267,7 +1267,7 @@ dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (dou
if(broke_oplock)
{
- free((char *)old_shares);
+ SAFE_FREE(old_shares);
num_share_modes = get_share_modes(conn, dev, inode, &old_shares);
}
} while(broke_oplock);
@@ -1288,7 +1288,6 @@ dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (dou
free_and_exit:
unlock_share_entry(conn, dev, inode);
- if(old_shares != NULL)
- free((char *)old_shares);
+ SAFE_FREE(old_shares);
return(ret);
}
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 7033eddc16..c17e63384f 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -701,8 +701,7 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval, B
if((outbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL)
{
DEBUG(0,("oplock_break: malloc fail for output buffer.\n"));
- free(inbuf);
- inbuf = NULL;
+ SAFE_FREE(inbuf);
return False;
}
@@ -840,8 +839,8 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval, B
file_chain_restore();
/* Free the buffers we've been using to recurse. */
- free(inbuf);
- free(outbuf);
+ SAFE_FREE(inbuf);
+ SAFE_FREE(outbuf);
/* We need this in case a readraw crossed on the wire. */
if(global_oplock_break)
@@ -1217,8 +1216,7 @@ void release_level_2_oplocks_on_change(files_struct *fsp)
}
}
- if (share_list)
- free((char *)share_list);
+ SAFE_FREE(share_list);
unlock_share_entry_fsp(fsp);
/* Paranoia check... */
diff --git a/source3/smbd/password.c b/source3/smbd/password.c
index 13a54cb704..a05735b4d7 100644
--- a/source3/smbd/password.c
+++ b/source3/smbd/password.c
@@ -71,9 +71,9 @@ void invalidate_vuid(uint16 vuid)
DLIST_REMOVE(validated_users, vuser);
- safe_free(vuser->groups);
+ SAFE_FREE(vuser->groups);
delete_nt_token(&vuser->nt_user_token);
- safe_free(vuser);
+ SAFE_FREE(vuser);
num_validated_vuids--;
}
@@ -139,7 +139,7 @@ NT_USER_TOKEN *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups,
num_sids = 5 + ngroups;
if ((token->user_sids = (DOM_SID *)malloc( num_sids*sizeof(DOM_SID))) == NULL) {
- free(token);
+ SAFE_FREE(token);
return NULL;
}
@@ -503,7 +503,7 @@ and given password ok\n", user));
}
}
- free(user_list);
+ SAFE_FREE(user_list);
}
/* check for a previously validated username/password pair */
diff --git a/source3/smbd/posix_acls.c b/source3/smbd/posix_acls.c
index 48fac44bbf..18a635336c 100644
--- a/source3/smbd/posix_acls.c
+++ b/source3/smbd/posix_acls.c
@@ -74,7 +74,7 @@ static void free_canon_ace_list( canon_ace *list_head )
while (list_head) {
canon_ace *old_head = list_head;
DLIST_REMOVE(list_head, list_head);
- free(old_head);
+ SAFE_FREE(old_head);
}
}
@@ -256,7 +256,7 @@ static void merge_aces( canon_ace **pp_list_head )
curr_ace_outer->perms |= curr_ace->perms;
DLIST_REMOVE(list_head, curr_ace);
- free(curr_ace);
+ SAFE_FREE(curr_ace);
curr_ace_outer_next = curr_ace_outer->next; /* We may have deleted the link. */
}
}
@@ -301,7 +301,7 @@ static void merge_aces( canon_ace **pp_list_head )
*/
DLIST_REMOVE(list_head, curr_ace);
- free(curr_ace);
+ SAFE_FREE(curr_ace);
curr_ace_outer_next = curr_ace_outer->next; /* We may have deleted the link. */
} else {
@@ -317,7 +317,7 @@ static void merge_aces( canon_ace **pp_list_head )
*/
DLIST_REMOVE(list_head, curr_ace_outer);
- free(curr_ace_outer);
+ SAFE_FREE(curr_ace_outer);
}
}
@@ -746,7 +746,7 @@ static BOOL create_canon_ace_lists(files_struct *fsp,
free_canon_ace_list(file_ace);
free_canon_ace_list(dir_ace);
- free(current_ace);
+ SAFE_FREE(current_ace);
DEBUG(0,("create_canon_ace_lists: unable to map SID %s to uid or gid.\n",
sid_to_string(str, &current_ace->sid) ));
return False;
@@ -816,7 +816,7 @@ static BOOL create_canon_ace_lists(files_struct *fsp,
Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name ));
free_canon_ace_list(file_ace);
free_canon_ace_list(dir_ace);
- free(current_ace);
+ SAFE_FREE(current_ace);
return False;
}
@@ -867,7 +867,7 @@ Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name ));
Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name ));
free_canon_ace_list(file_ace);
free_canon_ace_list(dir_ace);
- free(current_ace);
+ SAFE_FREE(current_ace);
return False;
}
@@ -883,8 +883,7 @@ Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name ));
* Free if ACE was not added.
*/
- if (current_ace)
- free(current_ace);
+ SAFE_FREE(current_ace);
}
if (fsp->is_directory && all_aces_are_inherit_only) {
@@ -1968,8 +1967,7 @@ size_t get_nt_acl(files_struct *fsp, SEC_DESC **ppdesc)
sys_acl_free_acl(dir_acl);
free_canon_ace_list(file_ace);
free_canon_ace_list(dir_ace);
- if (nt_ace_list)
- free(nt_ace_list);
+ SAFE_FREE(nt_ace_list);
return sd_size;
}
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index bf9e6457af..acda7128ae 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -87,7 +87,7 @@ static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len)
if(msg->msg_buf == NULL)
{
DEBUG(0,("push_message: malloc fail (2)\n"));
- free((char *)msg);
+ SAFE_FREE(msg);
return False;
}
@@ -180,8 +180,8 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
memcpy(buffer, msg->msg_buf, MIN(buffer_len, msg->msg_len));
/* Free the message we just copied. */
- free((char *)msg->msg_buf);
- free((char *)msg);
+ SAFE_FREE(msg->msg_buf);
+ SAFE_FREE(msg);
DEBUG(5,("receive_message_or_smb: returning queued smb message.\n"));
return True;
diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c
index 5d82756f24..3ef04b0692 100644
--- a/source3/smbd/quotas.c
+++ b/source3/smbd/quotas.c
@@ -413,7 +413,7 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B
DEBUG(5,("nfs_quotas: For path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n",args.gqa_pathp,(double)*bsize,(double)*dfree,(double)*dsize));
- safe_free(cutstr);
+ SAFE_FREE(cutstr);
DEBUG(10,("nfs_quotas: End of nfs_quotas\n" ));
return ret;
}
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 3dca209581..8527ebbe34 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -3051,7 +3051,7 @@ int reply_printqueue(connection_struct *conn,
SSVAL(smb_buf(outbuf),1,28*count);
}
- if (queue) free(queue);
+ SAFE_FREE(queue);
DEBUG(3,("%d entries returned in queue\n",count));
}
diff --git a/source3/smbd/sec_ctx.c b/source3/smbd/sec_ctx.c
index e0e392decc..72e23306ec 100644
--- a/source3/smbd/sec_ctx.c
+++ b/source3/smbd/sec_ctx.c
@@ -157,7 +157,7 @@ int get_current_groups(int *p_ngroups, gid_t **p_groups)
}
if ((ngroups = sys_getgroups(ngroups,groups)) == -1) {
- safe_free(groups);
+ SAFE_FREE(groups);
return -1;
}
@@ -181,11 +181,10 @@ void delete_nt_token(NT_USER_TOKEN **pptoken)
{
if (*pptoken) {
NT_USER_TOKEN *ptoken = *pptoken;
- safe_free( ptoken->user_sids );
+ SAFE_FREE( ptoken->user_sids );
ZERO_STRUCTP(ptoken);
}
- safe_free(*pptoken);
- *pptoken = NULL;
+ SAFE_FREE(*pptoken);
}
/****************************************************************************
@@ -205,7 +204,7 @@ NT_USER_TOKEN *dup_nt_token(NT_USER_TOKEN *ptoken)
ZERO_STRUCTP(token);
if ((token->user_sids = (DOM_SID *)memdup( ptoken->user_sids, sizeof(DOM_SID) * ptoken->num_sids )) == NULL) {
- free(token);
+ SAFE_FREE(token);
return NULL;
}
@@ -244,8 +243,7 @@ BOOL initialise_groups(char *user, uid_t uid, gid_t gid)
prev_ctx_p = &sec_ctx_stack[sec_ctx_stack_ndx - 1];
- safe_free(prev_ctx_p->groups);
- prev_ctx_p->groups = NULL;
+ SAFE_FREE(prev_ctx_p->groups);
prev_ctx_p->ngroups = 0;
get_current_groups(&prev_ctx_p->ngroups, &prev_ctx_p->groups);
@@ -336,7 +334,7 @@ void set_sec_ctx(uid_t uid, gid_t gid, int ngroups, gid_t *groups, NT_USER_TOKEN
ctx_p->ngroups = ngroups;
- safe_free(ctx_p->groups);
+ SAFE_FREE(ctx_p->groups);
if (token && (token == ctx_p->token))
smb_panic("DUPLICATE_TOKEN");
@@ -393,7 +391,7 @@ BOOL pop_sec_ctx(void)
ctx_p->uid = (uid_t)-1;
ctx_p->gid = (gid_t)-1;
- safe_free(ctx_p->groups);
+ SAFE_FREE(ctx_p->groups);
ctx_p->ngroups = 0;
delete_nt_token(&ctx_p->token);
diff --git a/source3/smbd/session.c b/source3/smbd/session.c
index 6a27cd7326..faf1bb249f 100644
--- a/source3/smbd/session.c
+++ b/source3/smbd/session.c
@@ -145,8 +145,7 @@ void session_yield(uint16 vuid)
memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
- safe_free(dbuf.dptr);
- dbuf.dptr = NULL;
+ SAFE_FREE(dbuf.dptr);
#if WITH_UTMP
if (lp_utmp()) {
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index cb4ca994f4..139b97d088 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -2466,10 +2466,8 @@ int reply_trans2(connection_struct *conn,
if ((total_params && !params) || (total_data && !data)) {
DEBUG(2,("Out of memory in reply_trans2\n"));
- if(params)
- free(params);
- if(data)
- free(data);
+ SAFE_FREE(params);
+ SAFE_FREE(data);
END_PROFILE(SMBtrans2);
return ERROR_DOS(ERRDOS,ERRnomem);
}
@@ -2508,10 +2506,8 @@ int reply_trans2(connection_struct *conn,
else
DEBUG(0,("reply_trans2: %s in getting secondary trans2 response.\n",
(smb_read_error == READ_ERROR) ? "error" : "timeout" ));
- if(params)
- free(params);
- if(data)
- free(data);
+ SAFE_FREE(params);
+ SAFE_FREE(data);
END_PROFILE(SMBtrans2);
return ERROR_DOS(ERRSRV,ERRerror);
}
@@ -2632,10 +2628,8 @@ int reply_trans2(connection_struct *conn,
default:
/* Error in request */
DEBUG(2,("Unknown request %d in trans2 call\n", tran_call));
- if(params)
- free(params);
- if(data)
- free(data);
+ SAFE_FREE(params);
+ SAFE_FREE(data);
END_PROFILE(SMBtrans2);
return ERROR_DOS(ERRSRV,ERRerror);
}
@@ -2647,10 +2641,8 @@ int reply_trans2(connection_struct *conn,
an error packet.
*/
- if(params)
- free(params);
- if(data)
- free(data);
+ SAFE_FREE(params);
+ SAFE_FREE(data);
END_PROFILE(SMBtrans2);
return outsize; /* If a correct response was needed the
call_trans2xxx calls have already sent
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index fce13bf13d..60762a0155 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -572,7 +572,7 @@ static void array_promote(char *array,int elsize,int element)
memcpy(p,array + element * elsize, elsize);
memmove(array + elsize,array,elsize*element);
memcpy(array,p,elsize);
- free(p);
+ SAFE_FREE(p);
}
/*******************************************************************
diff --git a/source3/smbwrapper/smbw.c b/source3/smbwrapper/smbw.c
index d5b61ac997..5702ea51ca 100644
--- a/source3/smbwrapper/smbw.c
+++ b/source3/smbwrapper/smbw.c
@@ -281,13 +281,13 @@ static char *smbw_find_workgroup(void)
slprintf(server, sizeof(server), "%s#1D", name);
if (smbw_server(server, "IPC$")) {
smbw_setshared("WORKGROUP", name);
- free(ip_list);
+ SAFE_FREE(ip_list);
return name;
}
}
}
- free(ip_list);
+ SAFE_FREE(ip_list);
return p;
}
@@ -606,9 +606,9 @@ struct smbw_server *smbw_server(char *server, char *share)
cli_shutdown(&c);
if (!srv) return NULL;
- if (srv->server_name) free(srv->server_name);
- if (srv->share_name) free(srv->share_name);
- free(srv);
+ SAFE_FREE(srv->server_name);
+ SAFE_FREE(srv->share_name);
+ SAFE_FREE(srv);
return NULL;
}
@@ -722,12 +722,10 @@ int smbw_open(const char *fname, int flags, mode_t mode)
}
if (file) {
if (file->f) {
- if (file->f->fname) {
- free(file->f->fname);
- }
- free(file->f);
+ SAFE_FREE(file->f->fname);
+ SAFE_FREE(file->f);
}
- free(file);
+ SAFE_FREE(file);
}
smbw_busy--;
return -1;
@@ -892,11 +890,11 @@ int smbw_close(int fd)
file->f->ref_count--;
if (file->f->ref_count == 0) {
- free(file->f->fname);
- free(file->f);
+ SAFE_FREE(file->f->fname);
+ SAFE_FREE(file->f);
}
ZERO_STRUCTP(file);
- free(file);
+ SAFE_FREE(file);
smbw_busy--;
@@ -1384,14 +1382,14 @@ static void smbw_srv_close(struct smbw_server *srv)
cli_shutdown(&srv->cli);
- free(srv->server_name);
- free(srv->share_name);
+ SAFE_FREE(srv->server_name);
+ SAFE_FREE(srv->share_name);
DLIST_REMOVE(smbw_srvs, srv);
ZERO_STRUCTP(srv);
- free(srv);
+ SAFE_FREE(srv);
smbw_busy--;
}
diff --git a/source3/smbwrapper/smbw_cache.c b/source3/smbwrapper/smbw_cache.c
index 3213d99941..13a68e7454 100644
--- a/source3/smbwrapper/smbw_cache.c
+++ b/source3/smbwrapper/smbw_cache.c
@@ -87,9 +87,9 @@ static void free_name_list(struct name_list *name_list)
next = tmp->next;
- free(tmp->name);
- free(tmp->comment);
- free(tmp);
+ SAFE_FREE(tmp->name);
+ SAFE_FREE(tmp->comment);
+ SAFE_FREE(tmp);
tmp = next;
}
diff --git a/source3/smbwrapper/smbw_dir.c b/source3/smbwrapper/smbw_dir.c
index d9dae454bb..6cbc34391f 100644
--- a/source3/smbwrapper/smbw_dir.c
+++ b/source3/smbwrapper/smbw_dir.c
@@ -64,12 +64,12 @@ free a smbw_dir structure and all entries
*******************************************************/
static void free_dir(struct smbw_dir *dir)
{
- if (dir->list) {
- free(dir->list);
- }
- if (dir->path) free(dir->path);
+ if(!dir) return;
+
+ SAFE_FREE(dir->list);
+ SAFE_FREE(dir->path);
ZERO_STRUCTP(dir);
- free(dir);
+ SAFE_FREE(dir);
}
static struct smbw_dir *cur_dir;
@@ -274,10 +274,8 @@ int smbw_dir_open(const char *fname)
return dir->fd;
failed:
- if (dir) {
- free_dir(dir);
- }
-
+ free_dir(dir);
+
return -1;
}