Change if(x)free(x); to free(x);

This commit is contained in:
Aaron Lehmann 2002-11-28 11:27:31 +00:00
parent 1652855fbc
commit a170e1c858
16 changed files with 47 additions and 95 deletions

View File

@ -491,13 +491,9 @@ void free_package(common_node_t *node)
unsigned short i; unsigned short i;
if (node) { if (node) {
for (i = 0; i < node->num_of_edges; i++) { for (i = 0; i < node->num_of_edges; i++) {
if (node->edge[i]) {
free(node->edge[i]); free(node->edge[i]);
} }
}
if (node->edge) {
free(node->edge); free(node->edge);
}
free(node); free(node);
} }
} }
@ -571,13 +567,9 @@ unsigned int fill_package_struct(char *control_buffer)
break; break;
} }
fill_package_struct_cleanup: fill_package_struct_cleanup:
if (field_name) {
free(field_name); free(field_name);
}
if (field_value) {
free(field_value); free(field_value);
} }
}
if (new_node->version == search_name_hashtable("unknown")) { if (new_node->version == search_name_hashtable("unknown")) {
free_package(new_node); free_package(new_node);
@ -880,9 +872,7 @@ void write_status_file(deb_file_t **deb_file)
fprintf(new_status_file, "%s\n\n", control_buffer); fprintf(new_status_file, "%s\n\n", control_buffer);
} }
if (status_from_file != NULL) {
free(status_from_file); free(status_from_file);
}
free(package_name); free(package_name);
free(control_buffer); free(control_buffer);
} }
@ -1661,10 +1651,8 @@ int dpkg_main(int argc, char **argv)
free(deb_file); free(deb_file);
for (i = 0; i < NAME_HASH_PRIME; i++) { for (i = 0; i < NAME_HASH_PRIME; i++) {
if (name_hashtable[i] != NULL) {
free(name_hashtable[i]); free(name_hashtable[i]);
} }
}
for (i = 0; i < PACKAGE_HASH_PRIME; i++) { for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
if (package_hashtable[i] != NULL) { if (package_hashtable[i] != NULL) {
@ -1673,10 +1661,8 @@ int dpkg_main(int argc, char **argv)
} }
for (i = 0; i < STATUS_HASH_PRIME; i++) { for (i = 0; i < STATUS_HASH_PRIME; i++) {
if (status_hashtable[i] != NULL) {
free(status_hashtable[i]); free(status_hashtable[i]);
} }
}
return(EXIT_SUCCESS); return(EXIT_SUCCESS);
} }

View File

@ -111,7 +111,7 @@ typedef unsigned long ulg;
# define ALLOC(type, array, size) { \ # define ALLOC(type, array, size) { \
array = (type*)xcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ array = (type*)xcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
} }
# define FREE(array) {if (array != NULL) free(array), array=NULL;} # define FREE(array) {free(array), array=NULL;}
#else #else
# define DECLARE(type, array, size) static type array[size] # define DECLARE(type, array, size) static type array[size]
# define ALLOC(type, array, size) # define ALLOC(type, array, size)

View File

@ -360,7 +360,6 @@ static void dfree(struct dnode **dnp)
cur = dnp[0]; cur = dnp[0];
while (cur != NULL) { while (cur != NULL) {
if (cur->fullname != NULL)
free(cur->fullname); /* free the filename */ free(cur->fullname); /* free the filename */
next = cur->next; next = cur->next;
free(cur); /* free the dnode */ free(cur); /* free the dnode */

View File

@ -650,7 +650,7 @@ static void clear_array(xhash *array) {
while (hi) { while (hi) {
thi = hi; thi = hi;
hi = hi->next; hi = hi->next;
if (thi->data.v.string) free(thi->data.v.string); free(thi->data.v.string);
free(thi); free(thi);
} }
array->items[i] = NULL; array->items[i] = NULL;
@ -661,7 +661,7 @@ static void clear_array(xhash *array) {
/* clear a variable */ /* clear a variable */
static var *clrvar(var *v) { static var *clrvar(var *v) {
if (v->string && !(v->type & VF_FSTR)) if (!(v->type & VF_FSTR))
free(v->string); free(v->string);
v->type &= VF_DONTTOUCH; v->type &= VF_DONTTOUCH;
@ -1504,7 +1504,7 @@ static void split_f0(void) {
return; return;
is_f0_split = TRUE; is_f0_split = TRUE;
if (fstrings) free(fstrings); free(fstrings);
fsrealloc(0); fsrealloc(0);
n = awk_split(getvar_s(V[F0]), &fsplitter.n, &fstrings); n = awk_split(getvar_s(V[F0]), &fsplitter.n, &fstrings);
fsrealloc(n); fsrealloc(n);
@ -2376,7 +2376,6 @@ re_cont:
X.rsm = (rstream *)hash_search(fdhash, L.s); X.rsm = (rstream *)hash_search(fdhash, L.s);
if (X.rsm) { if (X.rsm) {
R.i = X.rsm->is_pipe ? pclose(X.rsm->F) : fclose(X.rsm->F); R.i = X.rsm->is_pipe ? pclose(X.rsm->F) : fclose(X.rsm->F);
if (X.rsm->buffer)
free(X.rsm->buffer); free(X.rsm->buffer);
hash_remove(fdhash, L.s); hash_remove(fdhash, L.s);
} }

View File

@ -130,7 +130,6 @@ static void destroy_cmd_strs(void)
regfree(sed_cmds[ncmds].sub_match); regfree(sed_cmds[ncmds].sub_match);
free(sed_cmds[ncmds].sub_match); free(sed_cmds[ncmds].sub_match);
} }
if (sed_cmds[ncmds].replace)
free(sed_cmds[ncmds].replace); free(sed_cmds[ncmds].replace);
} }

View File

@ -19,7 +19,7 @@
*/ */
static const char vi_Version[] = static const char vi_Version[] =
"$Id: vi.c,v 1.24 2002/10/26 10:19:19 andersen Exp $"; "$Id: vi.c,v 1.25 2002/11/28 11:27:23 aaronl Exp $";
/* /*
* To compile for standalone use: * To compile for standalone use:
@ -383,7 +383,6 @@ extern int vi_main(int argc, char **argv)
} else { } else {
for (; optind < argc; optind++) { for (; optind < argc; optind++) {
editing = 1; // 0=exit, 1=one file, 2+ =many files editing = 1; // 0=exit, 1=one file, 2+ =many files
if (cfn != 0)
free(cfn); free(cfn);
cfn = (Byte *) xstrdup(argv[optind]); cfn = (Byte *) xstrdup(argv[optind]);
edit_file(cfn); edit_file(cfn);
@ -490,9 +489,7 @@ static void edit_file(Byte * fn)
offset = 0; // no horizontal offset offset = 0; // no horizontal offset
c = '\0'; c = '\0';
#ifdef CONFIG_FEATURE_VI_DOT_CMD #ifdef CONFIG_FEATURE_VI_DOT_CMD
if (last_modifying_cmd != 0)
free(last_modifying_cmd); free(last_modifying_cmd);
if (ioq_start != NULL)
free(ioq_start); free(ioq_start);
ioq = ioq_start = last_modifying_cmd = 0; ioq = ioq_start = last_modifying_cmd = 0;
adding2q = 0; adding2q = 0;
@ -998,7 +995,6 @@ static void colon(Byte * buf)
// There is a read-able regular file // There is a read-able regular file
// make this the current file // make this the current file
q = (Byte *) xstrdup((char *) fn); // save the cfn q = (Byte *) xstrdup((char *) fn); // save the cfn
if (cfn != 0)
free(cfn); // free the old name free(cfn); // free the old name
cfn = q; // remember new cfn cfn = q; // remember new cfn
@ -1048,7 +1044,6 @@ static void colon(Byte * buf)
} }
if (strlen((char *) args) > 0) { if (strlen((char *) args) > 0) {
// user wants a new filename // user wants a new filename
if (cfn != NULL)
free(cfn); free(cfn);
cfn = (Byte *) xstrdup((char *) args); cfn = (Byte *) xstrdup((char *) args);
} else { } else {
@ -1635,7 +1630,6 @@ static Byte *new_screen(int ro, int co)
{ {
int li; int li;
if (screen != 0)
free(screen); free(screen);
screensize = ro * co + 8; screensize = ro * co + 8;
screen = (Byte *) xmalloc(screensize); screen = (Byte *) xmalloc(screensize);
@ -1652,10 +1646,7 @@ static Byte *new_text(int size)
{ {
if (size < 10240) if (size < 10240)
size = 10240; // have a minimum size for new files size = 10240; // have a minimum size for new files
if (text != 0) {
//text -= 4;
free(text); free(text);
}
text = (Byte *) xmalloc(size + 8); text = (Byte *) xmalloc(size + 8);
memset(text, '\0', size); // clear new text[] memset(text, '\0', size); // clear new text[]
//text += 4; // leave some room for "oops" //text += 4; // leave some room for "oops"
@ -2171,7 +2162,6 @@ extern inline void print_literal(Byte * buf, Byte * s) // copy s to buf, convert
static void start_new_cmd_q(Byte c) static void start_new_cmd_q(Byte c)
{ {
// release old cmd // release old cmd
if (last_modifying_cmd != 0)
free(last_modifying_cmd); free(last_modifying_cmd);
// get buffer for new cmd // get buffer for new cmd
last_modifying_cmd = (Byte *) xmalloc(BUFSIZ); last_modifying_cmd = (Byte *) xmalloc(BUFSIZ);
@ -2227,9 +2217,7 @@ static Byte *text_yank(Byte * p, Byte * q, int dest) // copy text into a registe
} }
cnt = q - p + 1; cnt = q - p + 1;
t = reg[dest]; t = reg[dest];
if (t != 0) { // if already a yank register free(t); // if already a yank register, free it
free(t); // free it
}
t = (Byte *) xmalloc(cnt + 1); // get a new register t = (Byte *) xmalloc(cnt + 1); // get a new register
memset(t, '\0', cnt + 1); // clear new text[] memset(t, '\0', cnt + 1); // clear new text[]
strncpy((char *) t, (char *) p, cnt); // copy text[] into bufer strncpy((char *) t, (char *) p, cnt); // copy text[] into bufer
@ -2615,7 +2603,6 @@ static Byte *get_input_line(Byte * prompt) // get input line- use "status line"
} }
} }
refresh(FALSE); refresh(FALSE);
if (obufp != NULL)
free(obufp); free(obufp);
obufp = (Byte *) xstrdup((char *) buf); obufp = (Byte *) xstrdup((char *) buf);
return (obufp); return (obufp);
@ -3454,9 +3441,7 @@ key_cmd_mode:
goto dc3; // if no pat re-use old pat goto dc3; // if no pat re-use old pat
if (strlen((char *) q) > 1) { // new pat- save it and find if (strlen((char *) q) > 1) { // new pat- save it and find
// there is a new pat // there is a new pat
if (last_search_pattern != 0) {
free(last_search_pattern); free(last_search_pattern);
}
last_search_pattern = (Byte *) xstrdup((char *) q); last_search_pattern = (Byte *) xstrdup((char *) q);
goto dc3; // now find the pattern goto dc3; // now find the pattern
} }

View File

@ -153,7 +153,6 @@ static void grep_file(FILE *file)
else { /* no match */ else { /* no match */
/* Add the line to the circular 'before' buffer */ /* Add the line to the circular 'before' buffer */
if(lines_before) { if(lines_before) {
if(before_buf[curpos])
free(before_buf[curpos]); free(before_buf[curpos]);
before_buf[curpos] = xstrdup(line); before_buf[curpos] = xstrdup(line);
curpos = (curpos + 1) % lines_before; curpos = (curpos + 1) % lines_before;
@ -225,7 +224,6 @@ static void destroy_regexes(void)
while (--nregexes >= 0) { while (--nregexes >= 0) {
regfree(&(regexes[nregexes])); regfree(&(regexes[nregexes]));
} }
if (regexes)
free(regexes); free(regexes);
} }
#endif #endif

View File

@ -186,7 +186,6 @@ struct group *__getgrent(int grp_fd)
members[member_num + 1] = NULL; members[member_num + 1] = NULL;
} }
#else /* !GR_SCALE_DYNAMIC */ #else /* !GR_SCALE_DYNAMIC */
if (members != NULL)
free(members); free(members);
members = (char **) malloc((member_num + 1) * sizeof(char *)); members = (char **) malloc((member_num + 1) * sizeof(char *));
for ( ; field_begin && *field_begin != '\0'; field_begin = ptr) { for ( ; field_begin && *field_begin != '\0'; field_begin = ptr) {

View File

@ -234,7 +234,7 @@
#ifndef MODUTILS_MODULE_H #ifndef MODUTILS_MODULE_H
static const int MODUTILS_MODULE_H = 1; static const int MODUTILS_MODULE_H = 1;
#ident "$Id: insmod.c,v 1.91 2002/10/10 04:20:21 andersen Exp $" #ident "$Id: insmod.c,v 1.92 2002/11/28 11:27:27 aaronl Exp $"
/* This file contains the structures used by the 2.0 and 2.1 kernels. /* This file contains the structures used by the 2.0 and 2.1 kernels.
We do not use the kernel headers directly because we do not wish We do not use the kernel headers directly because we do not wish
@ -455,7 +455,7 @@ int delete_module(const char *);
#ifndef MODUTILS_OBJ_H #ifndef MODUTILS_OBJ_H
static const int MODUTILS_OBJ_H = 1; static const int MODUTILS_OBJ_H = 1;
#ident "$Id: insmod.c,v 1.91 2002/10/10 04:20:21 andersen Exp $" #ident "$Id: insmod.c,v 1.92 2002/11/28 11:27:27 aaronl Exp $"
/* The relocatable object is manipulated using elfin types. */ /* The relocatable object is manipulated using elfin types. */
@ -3589,7 +3589,6 @@ extern int insmod_main( int argc, char **argv)
flag_export = 0; flag_export = 0;
break; break;
case 'o': /* name the output module */ case 'o': /* name the output module */
if(m_name) /* Hmmm, duplicate "-o name". */
free(m_name); free(m_name);
m_name = xstrdup(optarg); m_name = xstrdup(optarg);
break; break;

View File

@ -246,7 +246,7 @@ int main(int argc, char *argv[])
switch (c) { switch (c) {
case 'c': case 'c':
len = strlen(optarg) > 255 ? 255 : strlen(optarg); len = strlen(optarg) > 255 ? 255 : strlen(optarg);
if (client_config.clientid) free(client_config.clientid); free(client_config.clientid);
client_config.clientid = xmalloc(len + 2); client_config.clientid = xmalloc(len + 2);
client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID;
client_config.clientid[OPT_LEN] = len; client_config.clientid[OPT_LEN] = len;
@ -262,7 +262,7 @@ int main(int argc, char *argv[])
case 'h': case 'h':
case 'H': case 'H':
len = strlen(optarg) > 255 ? 255 : strlen(optarg); len = strlen(optarg) > 255 ? 255 : strlen(optarg);
if (client_config.hostname) free(client_config.hostname); free(client_config.hostname);
client_config.hostname = xmalloc(len + 2); client_config.hostname = xmalloc(len + 2);
client_config.hostname[OPT_CODE] = DHCP_HOST_NAME; client_config.hostname[OPT_CODE] = DHCP_HOST_NAME;
client_config.hostname[OPT_LEN] = len; client_config.hostname[OPT_LEN] = len;

View File

@ -38,7 +38,7 @@ static int read_str(char *line, void *arg)
{ {
char **dest = arg; char **dest = arg;
if (*dest) free(*dest); free(*dest);
*dest = strdup(line); *dest = strdup(line);
return 1; return 1;

View File

@ -810,7 +810,7 @@ static void b_reset(o_string *o)
static void b_free(o_string *o) static void b_free(o_string *o)
{ {
b_reset(o); b_reset(o);
if (o->data != NULL) free(o->data); free(o->data);
o->data = NULL; o->data = NULL;
o->maxlen = 0; o->maxlen = 0;
} }
@ -880,7 +880,6 @@ static inline void setup_prompt_string(int promptmode, char **prompt_str)
#ifndef CONFIG_FEATURE_SH_FANCY_PROMPT #ifndef CONFIG_FEATURE_SH_FANCY_PROMPT
/* Set up the prompt */ /* Set up the prompt */
if (promptmode == 1) { if (promptmode == 1) {
if (PS1)
free(PS1); free(PS1);
PS1=xmalloc(strlen(cwd)+4); PS1=xmalloc(strlen(cwd)+4);
sprintf(PS1, "%s %s", cwd, ( geteuid() != 0 ) ? "$ ":"# "); sprintf(PS1, "%s %s", cwd, ( geteuid() != 0 ) ? "$ ":"# ");

View File

@ -518,11 +518,8 @@ static void free_job(struct job *cmd)
if (cmd->progs[i].redirects) if (cmd->progs[i].redirects)
free(cmd->progs[i].redirects); free(cmd->progs[i].redirects);
} }
if (cmd->progs)
free(cmd->progs); free(cmd->progs);
if (cmd->text)
free(cmd->text); free(cmd->text);
if (cmd->cmdbuf)
free(cmd->cmdbuf); free(cmd->cmdbuf);
keep = cmd->job_list; keep = cmd->job_list;
memset(cmd, 0, sizeof(struct job)); memset(cmd, 0, sizeof(struct job));
@ -677,7 +674,6 @@ static inline void setup_prompt_string(char **prompt_str)
#ifndef CONFIG_FEATURE_SH_FANCY_PROMPT #ifndef CONFIG_FEATURE_SH_FANCY_PROMPT
/* Set up the prompt */ /* Set up the prompt */
if (shell_context == 0) { if (shell_context == 0) {
if (PS1)
free(PS1); free(PS1);
PS1=xmalloc(strlen(cwd)+4); PS1=xmalloc(strlen(cwd)+4);
sprintf(PS1, "%s %s", cwd, ( geteuid() != 0 ) ? "$ ":"# "); sprintf(PS1, "%s %s", cwd, ( geteuid() != 0 ) ? "$ ":"# ");

View File

@ -1314,10 +1314,8 @@ static void free_name_list(void)
if (name_list) { if (name_list) {
for (i = 0; i < MAX_DEPTH; i++) { for (i = 0; i < MAX_DEPTH; i++) {
if (name_list[i]) {
free(name_list[i]); free(name_list[i]);
} }
}
free(name_list); free(name_list);
} }
} }

View File

@ -92,7 +92,6 @@ const char *normalize(const char *arg)
const char *argptr=arg; const char *argptr=arg;
char *bufptr; char *bufptr;
if (BUFFER != NULL)
free(BUFFER); free(BUFFER);
if (!quote) { /* Just copy arg */ if (!quote) { /* Just copy arg */
@ -340,7 +339,6 @@ int getopt_main(int argc, char *argv[])
alternative=1; alternative=1;
break; break;
case 'o': case 'o':
if (optstr)
free(optstr); free(optstr);
optstr=xstrdup(optarg); optstr=xstrdup(optarg);
break; break;
@ -348,7 +346,6 @@ int getopt_main(int argc, char *argv[])
add_long_options(optarg); add_long_options(optarg);
break; break;
case 'n': case 'n':
if (name)
free(name); free(name);
name=xstrdup(optarg); name=xstrdup(optarg);
break; break;

View File

@ -158,9 +158,7 @@ static void mtab_free(void)
this = mtab_cache; this = mtab_cache;
while (this) { while (this) {
next = this->next; next = this->next;
if (this->device)
free(this->device); free(this->device);
if (this->mountpt)
free(this->mountpt); free(this->mountpt);
free(this); free(this);
this = next; this = next;