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;
if (node) {
for (i = 0; i < node->num_of_edges; i++) {
if (node->edge[i]) {
free(node->edge[i]);
}
}
if (node->edge) {
free(node->edge);
}
free(node);
}
}
@ -571,13 +567,9 @@ unsigned int fill_package_struct(char *control_buffer)
break;
}
fill_package_struct_cleanup:
if (field_name) {
free(field_name);
}
if (field_value) {
free(field_value);
}
}
if (new_node->version == search_name_hashtable("unknown")) {
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);
}
if (status_from_file != NULL) {
free(status_from_file);
}
free(package_name);
free(control_buffer);
}
@ -1661,10 +1651,8 @@ int dpkg_main(int argc, char **argv)
free(deb_file);
for (i = 0; i < NAME_HASH_PRIME; i++) {
if (name_hashtable[i] != NULL) {
free(name_hashtable[i]);
}
}
for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
if (package_hashtable[i] != NULL) {
@ -1673,10 +1661,8 @@ int dpkg_main(int argc, char **argv)
}
for (i = 0; i < STATUS_HASH_PRIME; i++) {
if (status_hashtable[i] != NULL) {
free(status_hashtable[i]);
}
}
return(EXIT_SUCCESS);
}

View File

@ -111,7 +111,7 @@ typedef unsigned long ulg;
# define ALLOC(type, array, size) { \
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
# define DECLARE(type, array, size) static type array[size]
# define ALLOC(type, array, size)

View File

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

View File

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

View File

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

View File

@ -19,7 +19,7 @@
*/
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:
@ -383,7 +383,6 @@ extern int vi_main(int argc, char **argv)
} else {
for (; optind < argc; optind++) {
editing = 1; // 0=exit, 1=one file, 2+ =many files
if (cfn != 0)
free(cfn);
cfn = (Byte *) xstrdup(argv[optind]);
edit_file(cfn);
@ -490,9 +489,7 @@ static void edit_file(Byte * fn)
offset = 0; // no horizontal offset
c = '\0';
#ifdef CONFIG_FEATURE_VI_DOT_CMD
if (last_modifying_cmd != 0)
free(last_modifying_cmd);
if (ioq_start != NULL)
free(ioq_start);
ioq = ioq_start = last_modifying_cmd = 0;
adding2q = 0;
@ -998,7 +995,6 @@ static void colon(Byte * buf)
// There is a read-able regular file
// make this the current file
q = (Byte *) xstrdup((char *) fn); // save the cfn
if (cfn != 0)
free(cfn); // free the old name
cfn = q; // remember new cfn
@ -1048,7 +1044,6 @@ static void colon(Byte * buf)
}
if (strlen((char *) args) > 0) {
// user wants a new filename
if (cfn != NULL)
free(cfn);
cfn = (Byte *) xstrdup((char *) args);
} else {
@ -1635,7 +1630,6 @@ static Byte *new_screen(int ro, int co)
{
int li;
if (screen != 0)
free(screen);
screensize = ro * co + 8;
screen = (Byte *) xmalloc(screensize);
@ -1652,10 +1646,7 @@ static Byte *new_text(int size)
{
if (size < 10240)
size = 10240; // have a minimum size for new files
if (text != 0) {
//text -= 4;
free(text);
}
text = (Byte *) xmalloc(size + 8);
memset(text, '\0', size); // clear new text[]
//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)
{
// release old cmd
if (last_modifying_cmd != 0)
free(last_modifying_cmd);
// get buffer for new cmd
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;
t = reg[dest];
if (t != 0) { // if already a yank register
free(t); // free it
}
free(t); // if already a yank register, free it
t = (Byte *) xmalloc(cnt + 1); // get a new register
memset(t, '\0', cnt + 1); // clear new text[]
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);
if (obufp != NULL)
free(obufp);
obufp = (Byte *) xstrdup((char *) buf);
return (obufp);
@ -3454,9 +3441,7 @@ key_cmd_mode:
goto dc3; // if no pat re-use old pat
if (strlen((char *) q) > 1) { // new pat- save it and find
// there is a new pat
if (last_search_pattern != 0) {
free(last_search_pattern);
}
last_search_pattern = (Byte *) xstrdup((char *) q);
goto dc3; // now find the pattern
}

View File

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

View File

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

View File

@ -234,7 +234,7 @@
#ifndef MODUTILS_MODULE_H
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.
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
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. */
@ -3589,7 +3589,6 @@ extern int insmod_main( int argc, char **argv)
flag_export = 0;
break;
case 'o': /* name the output module */
if(m_name) /* Hmmm, duplicate "-o name". */
free(m_name);
m_name = xstrdup(optarg);
break;

View File

@ -246,7 +246,7 @@ int main(int argc, char *argv[])
switch (c) {
case 'c':
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[OPT_CODE] = DHCP_CLIENT_ID;
client_config.clientid[OPT_LEN] = len;
@ -262,7 +262,7 @@ int main(int argc, char *argv[])
case 'h':
case 'H':
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[OPT_CODE] = DHCP_HOST_NAME;
client_config.hostname[OPT_LEN] = len;

View File

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

View File

@ -810,7 +810,7 @@ static void b_reset(o_string *o)
static void b_free(o_string *o)
{
b_reset(o);
if (o->data != NULL) free(o->data);
free(o->data);
o->data = NULL;
o->maxlen = 0;
}
@ -880,7 +880,6 @@ static inline void setup_prompt_string(int promptmode, char **prompt_str)
#ifndef CONFIG_FEATURE_SH_FANCY_PROMPT
/* Set up the prompt */
if (promptmode == 1) {
if (PS1)
free(PS1);
PS1=xmalloc(strlen(cwd)+4);
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)
free(cmd->progs[i].redirects);
}
if (cmd->progs)
free(cmd->progs);
if (cmd->text)
free(cmd->text);
if (cmd->cmdbuf)
free(cmd->cmdbuf);
keep = cmd->job_list;
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
/* Set up the prompt */
if (shell_context == 0) {
if (PS1)
free(PS1);
PS1=xmalloc(strlen(cwd)+4);
sprintf(PS1, "%s %s", cwd, ( geteuid() != 0 ) ? "$ ":"# ");

View File

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

View File

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

View File

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