Skip to content

Commit

Permalink
Remove null-pointer checks before free()
Browse files Browse the repository at this point in the history
These are unnecessary, and the coding style was used inconsistently
and randomly.
  • Loading branch information
petere committed Oct 11, 2021
1 parent 4e4e580 commit e1547d0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
3 changes: 1 addition & 2 deletions test/test_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ static const char *run_hash(const char *str, const char *hexstr, const struct Di

digest_free(ctx);

if (buf)
free(buf);
free(buf);

if (memcmp(res, res2, reslen) != 0)
return "FAIL";
Expand Down
3 changes: 1 addition & 2 deletions test/test_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,7 @@ static const char *do_verify(const char *hostname, const char *commonName, ...)
va_end(ap);

ret = tls_check_servername(&ctx, &cert, hostname);
if (ctx.errmsg)
free(ctx.errmsg);
free(ctx.errmsg);
if (ret == 0)
return "OK";
if (ret == -1)
Expand Down
3 changes: 1 addition & 2 deletions test/tinytest_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ test_memcpy(void *ptr)

end:
/* This time our end block has something to do. */
if (mem)
free(mem);
free(mem);
}

/* ============================================================ */
Expand Down
12 changes: 4 additions & 8 deletions usual/cfparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ static bool load_handler(void *arg, bool is_sect, const char *key, const char *v
struct LoaderCtx *ctx = arg;

if (is_sect) {
if (ctx->cur_sect)
free(ctx->cur_sect);
free(ctx->cur_sect);
ctx->cur_sect = strdup(key);
if (!ctx->cur_sect)
return false;
Expand All @@ -391,8 +390,7 @@ bool cf_load_file(const struct CfContext *cf, const char *fn)
ctx.cf = cf;

ok = parse_ini_file(fn, load_handler, &ctx);
if (ctx.cur_sect)
free(ctx.cur_sect);
free(ctx.cur_sect);
if (ok && !ctx.got_main_sect) {
log_error("load_init_file: main section missing from config file");
return false;
Expand Down Expand Up @@ -449,8 +447,7 @@ bool cf_set_str(struct CfValue *cv, const char *value)
log_error("cf_set_str: no mem");
return false;
}
if (*dst_p)
free(*dst_p);
free(*dst_p);
*dst_p = tmp;
return true;
}
Expand Down Expand Up @@ -506,8 +503,7 @@ bool cf_set_filename(struct CfValue *cv, const char *value)

log_debug("expanded '%s' -> '%s'", value, tmp);

if (*dst_p)
free(*dst_p);
free(*dst_p);
*dst_p = tmp;
return true;
fail:
Expand Down
3 changes: 1 addition & 2 deletions usual/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ static void write_pidfile(const char *pidfile, bool first_write)
if (!pidfile || !pidfile[0])
return;

if (g_pidfile)
free(g_pidfile);
free(g_pidfile);
g_pidfile = strdup(pidfile);
if (!g_pidfile)
die("out of memory");
Expand Down

0 comments on commit e1547d0

Please sign in to comment.