From 423c3955d97dc84986be08ed0074d8eb58c624ef Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Fri, 25 Apr 2014 17:38:08 -0400 Subject: * various: Assume ISO C89-compliant free() implementation. --- dir.c | 9 +-------- expand.c | 4 +--- function.c | 2 +- job.c | 6 ++---- main.c | 18 ++++++------------ read.c | 30 ++++++++++-------------------- rule.c | 3 +-- variable.c | 24 +++++++----------------- w32/subproc/sub_proc.c | 10 +++++----- 9 files changed, 34 insertions(+), 72 deletions(-) diff --git a/dir.c b/dir.c index 77b7bfe..01373b3 100644 --- a/dir.c +++ b/dir.c @@ -1172,13 +1172,6 @@ read_dirstream (__ptr_t stream) return 0; } -static void -ansi_free (void *p) -{ - if (p) - free (p); -} - /* On 64 bit ReliantUNIX (5.44 and above) in LFS mode, stat() is actually a * macro for stat64(). If stat is a macro, make a local wrapper function to * invoke it. @@ -1224,7 +1217,7 @@ dir_setup_glob (glob_t *gl) { gl->gl_opendir = open_dirstream; gl->gl_readdir = read_dirstream; - gl->gl_closedir = ansi_free; + gl->gl_closedir = free; gl->gl_stat = local_stat; /* We don't bother setting gl_lstat, since glob never calls it. The slot is only there for compatibility with 4.4 BSD. */ diff --git a/expand.c b/expand.c index 28ec198..e4b08f1 100644 --- a/expand.c +++ b/expand.c @@ -377,7 +377,6 @@ variable_expand_string (char *line, const char *string, long length) Look up the value of the variable. */ o = reference_variable (o, beg, end - beg); - if (abeg) free (abeg); } break; @@ -447,8 +446,7 @@ expand_argument (const char *str, const char *end) r = allocated_variable_expand (tmp); - if (alloc) - free (alloc); + free (alloc); return r; } diff --git a/function.c b/function.c index bb62187..9c0a036 100644 --- a/function.c +++ b/function.c @@ -2425,7 +2425,7 @@ handle_function (char **op, const char **stringp) if (entry_p->expand_args) for (argvp=argv; *argvp != 0; ++argvp) free (*argvp); - else if (abeg) + else free (abeg); return 1; diff --git a/job.c b/job.c index 1850fe1..f75c7f2 100644 --- a/job.c +++ b/job.c @@ -2715,10 +2715,8 @@ construct_command_argv_internal (char *line, char **restp, const char *shell, slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : "")); - if (s1) - free (s1); - if (s2) - free (s2); + free (s1); + free (s2); } if (slow_flag) goto slow; diff --git a/main.c b/main.c index 4659099..e5f7d38 100644 --- a/main.c +++ b/main.c @@ -996,8 +996,7 @@ find_and_set_default_shell (const char *token) batch_mode_shell = 1; #endif - if (atoken) - free (atoken); + free (atoken); return (sh_found); } @@ -2405,9 +2404,8 @@ main (int argc, char **argv, char **envp) db_level = orig_db_level; - /* Free the makefile mtimes (if we allocated any). */ - if (makefile_mtimes) - free (makefile_mtimes); + /* Free the makefile mtimes. */ + free (makefile_mtimes); } /* Set up 'MAKEFLAGS' again for the normal targets. */ @@ -2793,8 +2791,7 @@ decode_switches (int argc, const char **argv, int env) if (cs->type == string) { char **val = (char **)cs->value_ptr; - if (*val) - free (*val); + free (*val); *val = xstrdup (coptarg); break; } @@ -3365,11 +3362,8 @@ clean_jobserver (int status) sub-makes. Also reset job_slots since it will be put on the command line, not in MAKEFLAGS. */ job_slots = default_job_slots; - if (jobserver_fds) - { - free (jobserver_fds); - jobserver_fds = 0; - } + free (jobserver_fds); + jobserver_fds = 0; } } diff --git a/read.c b/read.c index efacaf5..1fe229b 100644 --- a/read.c +++ b/read.c @@ -307,10 +307,8 @@ static void restore_conditionals (struct conditionals *saved) { /* Free any space allocated by conditional_line. */ - if (conditionals->ignoring) - free (conditionals->ignoring); - if (conditionals->seen_else) - free (conditionals->seen_else); + free (conditionals->ignoring); + free (conditionals->seen_else); /* Restore state. */ conditionals = saved; @@ -409,8 +407,7 @@ eval_makefile (const char *filename, int flags) if (flags & RM_DONTCARE) deps->dontcare = 1; - if (expanded) - free (expanded); + free (expanded); /* If the makefile can't be found at all, give up entirely. */ @@ -707,8 +704,7 @@ eval (struct ebuffer *ebuf, int set_default) if (collapsed_length < linelen+1) { collapsed_length = linelen+1; - if (collapsed) - free (collapsed); + free (collapsed); /* Don't need xrealloc: we don't need to preserve the content. */ collapsed = xmalloc (collapsed_length); } @@ -856,8 +852,7 @@ eval (struct ebuffer *ebuf, int set_default) /* No pattern means remove all previous selective VPATH's. */ vpat = 0; construct_vpath_list (vpat, p); - if (vpat != 0) - free (vpat); + free (vpat); continue; } @@ -1401,8 +1396,7 @@ eval (struct ebuffer *ebuf, int set_default) /* At eof, record the last rule. */ record_waiting_files (); - if (collapsed) - free (collapsed); + free (collapsed); free (commands); } @@ -1918,8 +1912,7 @@ record_target_var (struct nameseq *filenames, char *defn, if (gv && v != gv && (gv->origin == o_env_override || gv->origin == o_command)) { - if (v->value != 0) - free (v->value); + free (v->value); v->value = xstrdup (gv->value); v->origin = gv->origin; v->recursive = gv->recursive; @@ -2854,8 +2847,7 @@ construct_include_path (const char **arg_dirs) dirs[idx++] = strcache_add_len (dir, len); } - if (expanded) - free (expanded); + free (expanded); } /* Now add the standard default dirs at the end. */ @@ -3347,12 +3339,10 @@ parse_file_seq (char **stringp, unsigned int size, int stopmap, globfree (&gl); #ifndef NO_ARCHIVES - if (arname) - free (arname); + free (arname); #endif - if (tildep) - free (tildep); + free (tildep); } *stringp = p; diff --git a/rule.c b/rule.c index 986ada7..2535bd6 100644 --- a/rule.c +++ b/rule.c @@ -140,8 +140,7 @@ count_implicit_rule_limits (void) rule = next; } - if (name != 0) - free (name); + free (name); } /* Create a pattern rule from a suffix rule. diff --git a/variable.c b/variable.c index 4df8d8d..3f57e7d 100644 --- a/variable.c +++ b/variable.c @@ -222,8 +222,7 @@ define_variable_in_set (const char *name, unsigned int length, than this one, don't redefine it. */ if ((int) origin >= (int) v->origin) { - if (v->value != 0) - free (v->value); + free (v->value); v->value = xstrdup (value); if (flocp != 0) v->fileinfo = *flocp; @@ -1233,8 +1232,7 @@ do_variable_definition (const gmk_floc *flocp, const char *varname, alloc_value[oldlen] = ' '; memcpy (&alloc_value[oldlen + 1], val, vallen + 1); - if (tp) - free (tp); + free (tp); } } } @@ -1359,8 +1357,7 @@ do_variable_definition (const gmk_floc *flocp, const char *varname, else v = lookup_variable (varname, strlen (varname)); - if (tp) - free (tp); + free (tp); } } else @@ -1380,8 +1377,7 @@ do_variable_definition (const gmk_floc *flocp, const char *varname, v->append = append; v->conditional = conditional; - if (alloc_value) - free (alloc_value); + free (alloc_value); return v->special ? set_special_var (v) : v; } @@ -1764,16 +1760,10 @@ sync_Path_environment (void) if (!path) return; - /* - * If done this before, don't leak memory unnecessarily. - * Free the previous entry before allocating new one. - */ - if (environ_path) - free (environ_path); + /* If done this before, free the previous entry before allocating new one. */ + free (environ_path); - /* - * Create something WINDOWS32 world can grok - */ + /* Create something WINDOWS32 world can grok. */ convert_Path_to_windows32 (path, ';'); environ_path = xstrdup (concat (3, "PATH", "=", path)); putenv (environ_path); diff --git a/w32/subproc/sub_proc.c b/w32/subproc/sub_proc.c index 34cc85d..88749da 100644 --- a/w32/subproc/sub_proc.c +++ b/w32/subproc/sub_proc.c @@ -767,7 +767,7 @@ process_begin( startInfo.hStdError = (HANDLE)pproc->sv_stderr[1]; if (as_user) { - if (envblk) free(envblk); + free(envblk); return -1; } else { DB (DB_JOBS, ("CreateProcess(%s,%s,...)\n", @@ -789,7 +789,7 @@ process_begin( pproc->lerrno = E_FORK; fprintf(stderr, "process_begin: CreateProcess(%s, %s, ...) failed.\n", exec_path ? exec_path : "NULL", command_line); - if (envblk) free(envblk); + free(envblk); free( command_line ); return(-1); } @@ -811,7 +811,7 @@ process_begin( pproc->sv_stderr[1] = 0; free( command_line ); - if (envblk) free(envblk); + free(envblk); pproc->lerrno=0; return 0; } @@ -1320,7 +1320,7 @@ make_command_line( char *shell_name, char *full_exec_path, char **argv) command_line = (char*) malloc(bytes_required); if (!command_line) { - if (enclose_in_quotes) free(enclose_in_quotes); + free(enclose_in_quotes); return NULL; } @@ -1413,7 +1413,7 @@ make_command_line( char *shell_name, char *full_exec_path, char **argv) */ *command_line_i = '\0'; - if (enclose_in_quotes) free(enclose_in_quotes); + free(enclose_in_quotes); return command_line; } -- cgit v1.2.3