From 88917b0f143e2eac468aea14338b4d9eddba389d Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Tue, 20 May 2008 20:39:38 +0000 Subject: replace "if (p) free(p)" by just "free(p)" - free(NULL) is safe. --- libc/misc/glob/glob.c | 3 +-- libc/misc/regex/regex_old.c | 11 ++++------- libc/misc/search/_hsearch_r.c | 5 ++--- libc/misc/wordexp/wordexp.c | 30 +++++++++++------------------- 4 files changed, 18 insertions(+), 31 deletions(-) (limited to 'libc/misc') diff --git a/libc/misc/glob/glob.c b/libc/misc/glob/glob.c index 00c49688f..8d3e3c450 100644 --- a/libc/misc/glob/glob.c +++ b/libc/misc/glob/glob.c @@ -482,8 +482,7 @@ static int glob_in_dir (const char *pattern, const char *directory, int flags, } while (names != NULL) { - if (names->name != NULL) - free (names->name); + free (names->name); names = names->next; } return GLOB_NOSPACE; diff --git a/libc/misc/regex/regex_old.c b/libc/misc/regex/regex_old.c index 57b97ae68..7a9c4d7e0 100644 --- a/libc/misc/regex/regex_old.c +++ b/libc/misc/regex/regex_old.c @@ -5132,7 +5132,7 @@ strong_alias(__re_search_2, re_search_2) #ifdef MATCH_MAY_ALLOCATE # define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL #else -# define FREE_VAR(var) if (var) free (var); var = NULL +# define FREE_VAR(var) free (var); var = NULL #endif #ifdef WCHAR @@ -8313,20 +8313,17 @@ void regfree (preg) regex_t *preg; { - if (preg->buffer != NULL) - free (preg->buffer); + free (preg->buffer); preg->buffer = NULL; preg->allocated = 0; preg->used = 0; - if (preg->fastmap != NULL) - free (preg->fastmap); + free (preg->fastmap); preg->fastmap = NULL; preg->fastmap_accurate = 0; - if (preg->translate != NULL) - free (preg->translate); + free (preg->translate); preg->translate = NULL; } #if defined _LIBC || defined __UCLIBC__ diff --git a/libc/misc/search/_hsearch_r.c b/libc/misc/search/_hsearch_r.c index 257c0610c..c9c4a9ccf 100644 --- a/libc/misc/search/_hsearch_r.c +++ b/libc/misc/search/_hsearch_r.c @@ -110,9 +110,8 @@ void hdestroy_r (struct hsearch_data *htab) return; } - if (htab->table != NULL) - /* free used memory */ - free (htab->table); + /* free used memory */ + free (htab->table); /* the sign for an existing table is an value != NULL in htable */ htab->table = NULL; diff --git a/libc/misc/wordexp/wordexp.c b/libc/misc/wordexp/wordexp.c index 6872a65ba..45d5a876e 100644 --- a/libc/misc/wordexp/wordexp.c +++ b/libc/misc/wordexp/wordexp.c @@ -1076,8 +1076,7 @@ parse_comm(char **word, size_t * word_length, size_t * max_length, } /* Premature end */ - if (comm) - free(comm); + free(comm); return WRDE_SYNTAX; } @@ -1370,8 +1369,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length, &buffer[20]); *word = w_addstr(*word, word_length, max_length, value); free(env); - if (pattern) - free(pattern); + free(pattern); return *word ? 0 : WRDE_NOSPACE; } /* Is it `$*' or `$@' (unquoted) ? */ @@ -1530,8 +1528,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length, if (free_value) free(value); - if (expanded) - free(expanded); + free(expanded); goto do_error; } @@ -1550,8 +1547,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length, if (free_value) free(value); - if (expanded) - free(expanded); + free(expanded); goto do_error; } @@ -1573,8 +1569,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length, goto no_space; } - if (pattern) - free(pattern); + free(pattern); pattern = expanded; } @@ -1723,7 +1718,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length, /* Substitute parameter */ break; - if (free_value && value) + if (free_value) free(value); if (!colon_seen && value) @@ -1740,7 +1735,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length, case ACT_NONNULL_SUBST: if (value && (*value || !colon_seen)) { - if (free_value && value) + if (free_value) free(value); value = pattern ? strdup(pattern) : pattern; @@ -1769,7 +1764,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length, goto success; } - if (free_value && value) + if (free_value) free(value); value = pattern ? strdup(pattern) : pattern; @@ -1895,11 +1890,9 @@ parse_param(char **word, size_t * word_length, size_t * max_length, error = WRDE_SYNTAX; do_error: - if (env) - free(env); + free(env); - if (pattern) - free(pattern); + free(pattern); return error; } @@ -2269,8 +2262,7 @@ int wordexp(const char *words, wordexp_t * we, int flags) * set we members back to what they were. */ - if (word != NULL) - free(word); + free(word); if (error == WRDE_NOSPACE) return WRDE_NOSPACE; -- cgit v1.2.3