diff options
author | Simo Sorce <idra@samba.org> | 2001-09-17 03:33:37 +0000 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2001-09-17 03:33:37 +0000 |
commit | bcbd75f7add425ebee760ddbd2e80a1d4a51e619 (patch) | |
tree | b434877ae75febe93b4a1cb67cd2585d8bfd2a1a | |
parent | 484a7c0341fe033fe26fe1e6b597ed1c456c39d4 (diff) | |
download | samba-bcbd75f7add425ebee760ddbd2e80a1d4a51e619.tar.gz samba-bcbd75f7add425ebee760ddbd2e80a1d4a51e619.tar.bz2 samba-bcbd75f7add425ebee760ddbd2e80a1d4a51e619.zip |
move to SAFE_FREE()
(This used to be commit 48fc6a6cd52e01b287030fbbf0aa08a6814c5e11)
-rw-r--r-- | source3/libsmb/clientgen.c | 16 | ||||
-rw-r--r-- | source3/libsmb/clifile.c | 4 | ||||
-rw-r--r-- | source3/libsmb/clilist.c | 12 | ||||
-rw-r--r-- | source3/libsmb/cliprint.c | 8 | ||||
-rw-r--r-- | source3/libsmb/clirap.c | 40 | ||||
-rw-r--r-- | source3/libsmb/clisecdesc.c | 8 | ||||
-rw-r--r-- | source3/libsmb/domain_client_validate.c | 3 | ||||
-rw-r--r-- | source3/libsmb/libsmbclient.c | 80 | ||||
-rw-r--r-- | source3/libsmb/namequery.c | 21 | ||||
-rw-r--r-- | source3/libsmb/nmblib.c | 40 |
10 files changed, 91 insertions, 141 deletions
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index 87c8348853..79757947b4 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -201,11 +201,11 @@ struct cli_state *cli_initialise(struct cli_state *cli) error: - safe_free(cli->inbuf); - safe_free(cli->outbuf); + SAFE_FREE(cli->inbuf); + SAFE_FREE(cli->outbuf); if (alloced_cli) - safe_free(cli); + SAFE_FREE(cli); return NULL; } @@ -215,14 +215,8 @@ shutdown a client structure ****************************************************************************/ void cli_shutdown(struct cli_state *cli) { - if (cli->outbuf) - { - free(cli->outbuf); - } - if (cli->inbuf) - { - free(cli->inbuf); - } + SAFE_FREE(cli->outbuf); + SAFE_FREE(cli->inbuf); if (cli->mem_ctx) talloc_destroy(cli->mem_ctx); diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index c6cf73bcf3..4e6a89a9ae 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -201,8 +201,8 @@ int cli_nt_delete_on_close(struct cli_state *cli, int fnum, BOOL flag) return False; } - if (rdata) free(rdata); - if (rparam) free(rparam); + SAFE_FREE(rdata); + SAFE_FREE(rparam); return True; } diff --git a/source3/libsmb/clilist.c b/source3/libsmb/clilist.c index a99bc91bfb..a9212c9dba 100644 --- a/source3/libsmb/clilist.c +++ b/source3/libsmb/clilist.c @@ -283,9 +283,9 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, total_received += ff_searchcount; - if (rdata) free(rdata); rdata = NULL; - if (rparam) free(rparam); rparam = NULL; - + SAFE_FREE(rdata); + SAFE_FREE(rparam); + DEBUG(3,("received %d entries (eos=%d)\n", ff_searchcount,ff_eos)); @@ -300,7 +300,7 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, } /* free up the dirlist buffer */ - if (dirlist) free(dirlist); + SAFE_FREE(dirlist); return(total_received); } @@ -394,7 +394,7 @@ int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute, if (!tdl) { DEBUG(0,("cli_list_old: failed to expand dirlist")); - if (dirlist) free(dirlist); + SAFE_FREE(dirlist); return 0; } else dirlist = tdl; @@ -446,7 +446,7 @@ int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute, fn(&finfo, Mask, state); } - if (dirlist) free(dirlist); + SAFE_FREE(dirlist); return(num_received); } diff --git a/source3/libsmb/cliprint.c b/source3/libsmb/cliprint.c index eb9c859806..57e2c049d8 100644 --- a/source3/libsmb/cliprint.c +++ b/source3/libsmb/cliprint.c @@ -112,8 +112,8 @@ int cli_print_queue(struct cli_state *cli, } /* If any parameters or data were returned, free the storage. */ - if(rparam) free(rparam); - if(rdata) free(rdata); + SAFE_FREE(rparam); + SAFE_FREE(rdata); return i; } @@ -149,8 +149,8 @@ int cli_printjob_del(struct cli_state *cli, int job) ret = SVAL(rparam,0); } - if (rparam) free(rparam); - if (rdata) free(rdata); + SAFE_FREE(rparam); + SAFE_FREE(rdata); return ret; } diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c index bfbe478191..90f4d546d1 100644 --- a/source3/libsmb/clirap.c +++ b/source3/libsmb/clirap.c @@ -124,10 +124,8 @@ BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation) } } - if (rparam) - free(rparam); - if (rdata) - free(rdata); + SAFE_FREE(rparam); + SAFE_FREE(rdata); return (cli->rap_error == 0); } @@ -193,10 +191,8 @@ int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, co DEBUG(4,("NetShareEnum failed\n")); } - if (rparam) - free(rparam); - if (rdata) - free(rdata); + SAFE_FREE(rparam); + SAFE_FREE(rdata); return count; } @@ -271,10 +267,8 @@ BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype, } } - if (rparam) - free(rparam); - if (rdata) - free(rdata); + SAFE_FREE(rparam); + SAFE_FREE(rdata); return(count > 0); } @@ -363,10 +357,8 @@ BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char cli->rap_error = SVAL(rparam,0); } - if (rparam) - free(rparam); - if (rdata) - free(rdata); + SAFE_FREE(rparam); + SAFE_FREE(rdata); return (cli->rap_error == 0); } @@ -445,8 +437,8 @@ BOOL cli_qpathinfo(struct cli_state *cli, const char *fname, *mode = SVAL(rdata,l1_attrFile); } - if (rdata) free(rdata); - if (rparam) free(rparam); + SAFE_FREE(rdata); + SAFE_FREE(rparam); return True; } @@ -515,8 +507,8 @@ BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname, *ino = IVAL(rdata, 64); } - if (rdata) free(rdata); - if (rparam) free(rparam); + SAFE_FREE(rdata); + SAFE_FREE(rparam); return True; } @@ -587,8 +579,8 @@ BOOL cli_qfileinfo(struct cli_state *cli, int fnum, *ino = IVAL(rdata, 64); } - if (rdata) free(rdata); - if (rparam) free(rparam); + SAFE_FREE(rdata); + SAFE_FREE(rparam); return True; } @@ -631,7 +623,7 @@ BOOL cli_qfileinfo_test(struct cli_state *cli, int fnum, int level, char *outdat memcpy(outdata, rdata, data_len); - if (rdata) free(rdata); - if (rparam) free(rparam); + SAFE_FREE(rdata); + SAFE_FREE(rparam); return True; } diff --git a/source3/libsmb/clisecdesc.c b/source3/libsmb/clisecdesc.c index e0d6ae809f..0e0884b843 100644 --- a/source3/libsmb/clisecdesc.c +++ b/source3/libsmb/clisecdesc.c @@ -65,8 +65,8 @@ SEC_DESC *cli_query_secdesc(struct cli_state *cli, int fnum, cleanup: - safe_free(rparam); - safe_free(rdata); + SAFE_FREE(rparam); + SAFE_FREE(rdata); prs_mem_free(&pd); return psd; @@ -122,8 +122,8 @@ BOOL cli_set_secdesc(struct cli_state *cli, int fnum, SEC_DESC *sd) cleanup: - safe_free(rparam); - safe_free(rdata); + SAFE_FREE(rparam); + SAFE_FREE(rdata); talloc_destroy(mem_ctx); diff --git a/source3/libsmb/domain_client_validate.c b/source3/libsmb/domain_client_validate.c index b23ab01c1d..90c15fd1f7 100644 --- a/source3/libsmb/domain_client_validate.c +++ b/source3/libsmb/domain_client_validate.c @@ -256,8 +256,7 @@ static BOOL find_connect_pdc(struct cli_state *pcli, } } - if(ip_list != NULL) - free((char *)ip_list); + SAFE_FREE(ip_list); return connected_ok; diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c index f7008a2680..9dca4637f4 100644 --- a/source3/libsmb/libsmbclient.c +++ b/source3/libsmb/libsmbclient.c @@ -393,9 +393,9 @@ struct smbc_server *smbc_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; } @@ -602,8 +602,7 @@ int smbc_open(const char *fname, int flags, mode_t mode) /* Handle the error ... */ - free(smbc_file_table[slot]); - smbc_file_table[slot] = NULL; + SAFE_FREE(smbc_file_table[slot]); errno = smbc_errno(&srv->cli); return -1; @@ -816,8 +815,8 @@ int smbc_close(int fd) } - if (fe->fname) free(fe->fname); - free(fe); + SAFE_FREE(fe->fname); + SAFE_FREE(fe); smbc_file_table[fd - smbc_start_fd] = NULL; return 0; @@ -1313,8 +1312,8 @@ static void smbc_remove_dir(struct smbc_file *dir) f = d; d = d->next; - if (f->dirent) free(f->dirent); - free(f); + SAFE_FREE(f->dirent); + SAFE_FREE(f); } @@ -1350,7 +1349,7 @@ static int add_dirent(struct smbc_file *dir, const char *name, const char *comme dir->dir_list = malloc(sizeof(struct smbc_dir_list)); if (!dir->dir_list) { - free(dirent); + SAFE_FREE(dirent); dir->dir_error = ENOMEM; return -1; @@ -1365,7 +1364,7 @@ static int add_dirent(struct smbc_file *dir, const char *name, const char *comme if (!dir->dir_end) { - free(dirent); + SAFE_FREE(dirent); dir->dir_error = ENOMEM; return -1; @@ -1519,10 +1518,9 @@ int smbc_opendir(const char *fname) errno = EINVAL; if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; return -1; } @@ -1559,10 +1557,9 @@ int smbc_opendir(const char *fname) if (!srv) { if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; return -1; } @@ -1575,10 +1572,9 @@ int smbc_opendir(const char *fname) (void *)smbc_file_table[slot])) { if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; errno = cli_errno(&srv->cli); return -1; @@ -1592,10 +1588,9 @@ int smbc_opendir(const char *fname) errno = EINVAL; if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; return -1; } @@ -1630,10 +1625,9 @@ int smbc_opendir(const char *fname) if (!srv) { if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; /* FIXME: Memory leaks ... */ return -1; } @@ -1646,10 +1640,9 @@ int smbc_opendir(const char *fname) (void *)smbc_file_table[slot])) { if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; errno = cli_errno(&srv->cli); return -1; @@ -1669,10 +1662,9 @@ int smbc_opendir(const char *fname) if (!srv) { if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; return -1; } @@ -1686,10 +1678,9 @@ int smbc_opendir(const char *fname) errno = cli_errno(&srv->cli); if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; return -1; } @@ -1699,10 +1690,9 @@ int smbc_opendir(const char *fname) errno = ENODEV; /* Neither the workgroup nor server exists */ if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; return -1; } @@ -1721,10 +1711,9 @@ int smbc_opendir(const char *fname) if (!srv) { if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; return -1; } @@ -1739,10 +1728,9 @@ int smbc_opendir(const char *fname) (void *)smbc_file_table[slot]) < 0) { if (smbc_file_table[slot]) { - if (smbc_file_table[slot]->fname) free(smbc_file_table[slot]->fname); - free(smbc_file_table[slot]); + SAFE_FREE(smbc_file_table[slot]->fname); + SAFE_FREE(smbc_file_table[slot]); } - smbc_file_table[slot] = NULL; errno = smbc_errno(&srv->cli); return -1; @@ -1790,8 +1778,8 @@ int smbc_closedir(int fd) if (fe) { - if (fe->fname) free(fe->fname); - free(fe); /* Free the space too */ + SAFE_FREE(fe->fname); + SAFE_FREE(fe); /* Free the space too */ } diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index 9dea4b7694..6fba488d66 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -184,7 +184,7 @@ BOOL name_status_find(int type, struct in_addr to_ip, char *name) pull_ascii(name, status[i].name, 15, 0, STR_TERMINATE); - free(status); + SAFE_FREE(status); return True; } @@ -273,7 +273,7 @@ BOOL name_register(int fd, const char *name, int name_type, if ((p2 = receive_nmb_packet(fd, 10, nmb->header.name_trn_id))) { debug_nmb_packet(p2); - free(p2); /* No memory leaks ... */ + SAFE_FREE(p2); /* No memory leaks ... */ } return True; @@ -405,8 +405,7 @@ struct in_addr *name_query(int fd,const char *name,int name_type, if (!tmp_ip_list) { DEBUG(0,("name_query: Realloc failed.\n")); - if (ip_list) - free(ip_list); + SAFE_FREE(ip_list); } ip_list = tmp_ip_list; @@ -871,7 +870,7 @@ static BOOL internal_resolve_name(const char *name, int name_type, } if((*return_iplist) != NULL) { - free((char *)(*return_iplist)); + SAFE_FREE(*return_iplist); *return_iplist = NULL; } return False; @@ -891,11 +890,10 @@ BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type) if(internal_resolve_name(name, name_type, &ip_list, &count)) { *return_ip = ip_list[0]; - free((char *)ip_list); + SAFE_FREE(ip_list); return True; } - if(ip_list != NULL) - free((char *)ip_list); + SAFE_FREE(ip_list); return False; } @@ -956,17 +954,16 @@ BOOL find_master_ip(char *group, struct in_addr *master_ip) if (internal_resolve_name(group, 0x1D, &ip_list, &count)) { *master_ip = ip_list[0]; - free((char *)ip_list); + SAFE_FREE(ip_list); return True; } if(internal_resolve_name(group, 0x1B, &ip_list, &count)) { *master_ip = ip_list[0]; - free((char *)ip_list); + SAFE_FREE((ip_list); return True; } - if(ip_list != NULL) - free((char *)ip_list); + SAFE_FREE(ip_list); return False; } diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c index 6a24cb382c..4ecc887524 100644 --- a/source3/libsmb/nmblib.c +++ b/source3/libsmb/nmblib.c @@ -345,8 +345,7 @@ static BOOL parse_alloc_res_rec(char *inbuf,int *offset,int length, int l = parse_nmb_name(inbuf,*offset,length,&(*recs)[i].rr_name); (*offset) += l; if (!l || (*offset)+10 > length) { - free(*recs); - *recs = NULL; + SAFE_FREE(*recs); return(False); } (*recs)[i].rr_type = RSVAL(inbuf,(*offset)); @@ -356,8 +355,7 @@ static BOOL parse_alloc_res_rec(char *inbuf,int *offset,int length, (*offset) += 10; if ((*recs)[i].rdlength>sizeof((*recs)[i].rdata) || (*offset)+(*recs)[i].rdlength > length) { - free(*recs); - *recs = NULL; + SAFE_FREE(*recs); return(False); } memcpy((*recs)[i].rdata,inbuf+(*offset),(*recs)[i].rdlength); @@ -580,19 +578,10 @@ static struct packet_struct *copy_nmb_packet(struct packet_struct *packet) free_and_exit: - if(copy_nmb->answers) { - free((char *)copy_nmb->answers); - copy_nmb->answers = NULL; - } - if(copy_nmb->nsrecs) { - free((char *)copy_nmb->nsrecs); - copy_nmb->nsrecs = NULL; - } - if(copy_nmb->additional) { - free((char *)copy_nmb->additional); - copy_nmb->additional = NULL; - } - free((char *)pkt_copy); + SAFE_FREE(copy_nmb->answers); + SAFE_FREE(copy_nmb->nsrecs); + SAFE_FREE(copy_nmb->additional); + SAFE_FREE(pkt_copy); DEBUG(0,("copy_nmb_packet: malloc fail in resource records.\n")); return NULL; @@ -640,18 +629,9 @@ struct packet_struct *copy_packet(struct packet_struct *packet) ******************************************************************/ static void free_nmb_packet(struct nmb_packet *nmb) { - if (nmb->answers) { - free(nmb->answers); - nmb->answers = NULL; - } - if (nmb->nsrecs) { - free(nmb->nsrecs); - nmb->nsrecs = NULL; - } - if (nmb->additional) { - free(nmb->additional); - nmb->additional = NULL; - } + SAFE_FREE(nmb->answers); + SAFE_FREE(nmb->nsrecs); + SAFE_FREE(nmb->additional); } /******************************************************************* @@ -674,7 +654,7 @@ void free_packet(struct packet_struct *packet) else if (packet->packet_type == DGRAM_PACKET) free_dgram_packet(&packet->packet.dgram); ZERO_STRUCTPN(packet); - free(packet); + SAFE_FREE(packet); } /******************************************************************* |