The C standard dictates that calling free(NULL) is a no-op. So we can safely assume this to be OK.
This patch removes the fatalx() call in xmalloc.c:xfree() and all callers of xfree() where they were previously checking for NULL have been removed. --- trunk/arguments.c | 12 ++++-------- trunk/array.h | 3 +-- trunk/cmd-command-prompt.c | 9 +++------ trunk/cmd-confirm-before.c | 3 +-- trunk/cmd-if-shell.c | 3 +-- trunk/cmd-string.c | 9 +++------ trunk/cmd.c | 27 +++++++++------------------ trunk/environ.c | 9 +++------ trunk/screen.c | 6 ++---- trunk/server-client.c | 19 ++++++------------- trunk/session.c | 6 ++---- trunk/status.c | 15 +++++---------- trunk/xmalloc.c | 2 -- 13 files changed, 40 insertions(+), 83 deletions(-) diff --git a/trunk/arguments.c b/trunk/arguments.c index 2710cef..4c94b0c 100644 --- a/trunk/arguments.c +++ b/trunk/arguments.c @@ -75,8 +75,7 @@ args_parse(const char *template, int argc, char **argv) bit_set(args->flags, opt); if (ptr[1] == ':') { - if (args->values[opt] != NULL) - xfree(args->values[opt]); + xfree(args->values[opt]); args->values[opt] = xstrdup(optarg); } } @@ -97,10 +96,8 @@ args_free(struct args *args) cmd_free_argv(args->argc, args->argv); - for (i = 0; i < SCHAR_MAX; i++) { - if (args->values[i] != NULL) - xfree(args->values[i]); - } + for (i = 0; i < SCHAR_MAX; i++) + xfree(args->values[i]); xfree(args->flags); xfree(args); @@ -182,8 +179,7 @@ args_has(struct args *args, u_char ch) void args_set(struct args *args, u_char ch, const char *value) { - if (args->values[ch] != NULL) - xfree(args->values[ch]); + xfree(args->values[ch]); if (value != NULL) args->values[ch] = xstrdup(value); else diff --git a/trunk/array.h b/trunk/array.h index 50f0da8..a9d4ad6 100644 --- a/trunk/array.h +++ b/trunk/array.h @@ -109,8 +109,7 @@ } while (0) #define ARRAY_FREE(a) do { \ - if ((a)->list != NULL) \ - xfree((a)->list); \ + xfree((a)->list); \ ARRAY_INIT(a); \ } while (0) #define ARRAY_FREEALL(a) do { \ diff --git a/trunk/cmd-command-prompt.c b/trunk/cmd-command-prompt.c index 55e69b3..747130f 100644 --- a/trunk/cmd-command-prompt.c +++ b/trunk/cmd-command-prompt.c @@ -205,11 +205,8 @@ cmd_command_prompt_free(void *data) { struct cmd_command_prompt_cdata *cdata = data; - if (cdata->inputs != NULL) - xfree(cdata->inputs); - if (cdata->prompts != NULL) - xfree(cdata->prompts); - if (cdata->template != NULL) - xfree(cdata->template); + xfree(cdata->inputs); + xfree(cdata->prompts); + xfree(cdata->template); xfree(cdata); } diff --git a/trunk/cmd-confirm-before.c b/trunk/cmd-confirm-before.c index 159b938..5436053 100644 --- a/trunk/cmd-confirm-before.c +++ b/trunk/cmd-confirm-before.c @@ -144,7 +144,6 @@ cmd_confirm_before_free(void *data) { struct cmd_confirm_before_data *cdata = data; - if (cdata->cmd != NULL) - xfree(cdata->cmd); + xfree(cdata->cmd); xfree(cdata); } diff --git a/trunk/cmd-if-shell.c b/trunk/cmd-if-shell.c index 220fc33..44a8ee5 100644 --- a/trunk/cmd-if-shell.c +++ b/trunk/cmd-if-shell.c @@ -115,8 +115,7 @@ cmd_if_shell_free(void *data) if (ctx->curclient != NULL) ctx->curclient->references--; - if (cdata->cmd_else != NULL) - xfree(cdata->cmd_else); + xfree(cdata->cmd_else); xfree(cdata->cmd_if); xfree(cdata); } diff --git a/trunk/cmd-string.c b/trunk/cmd-string.c index 0dd2a77..64c2283 100644 --- a/trunk/cmd-string.c +++ b/trunk/cmd-string.c @@ -170,8 +170,7 @@ error: xasprintf(cause, "invalid or unknown command: %s", s); out: - if (buf != NULL) - xfree(buf); + xfree(buf); if (argv != NULL) { for (i = 0; i < argc; i++) @@ -239,8 +238,7 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc) return (buf); error: - if (buf != NULL) - xfree(buf); + xfree(buf); return (NULL); } @@ -309,8 +307,7 @@ cmd_string_variable(const char *s, size_t *p) return (xstrdup(envent->value)); error: - if (buf != NULL) - xfree(buf); + xfree(buf); return (NULL); } diff --git a/trunk/cmd.c b/trunk/cmd.c index 7aefeff..5941692 100644 --- a/trunk/cmd.c +++ b/trunk/cmd.c @@ -196,10 +196,8 @@ cmd_free_argv(int argc, char **argv) if (argc == 0) return; - for (i = 0; i < argc; i++) { - if (argv[i] != NULL) - xfree(argv[i]); - } + for (i = 0; i < argc; i++) + xfree(argv[i]); xfree(argv); } @@ -289,8 +287,7 @@ cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx) void cmd_free(struct cmd *cmd) { - if (cmd->args != NULL) - args_free(cmd->args); + args_free(cmd->args); xfree(cmd); } @@ -897,8 +894,7 @@ no_session: ctx->error(ctx, "multiple sessions: %s", arg); else ctx->error(ctx, "session not found: %s", arg); - if (sessptr != NULL) - xfree(sessptr); + xfree(sessptr); return (NULL); not_found: @@ -906,8 +902,7 @@ not_found: ctx->error(ctx, "multiple windows: %s", arg); else ctx->error(ctx, "window not found: %s", arg); - if (sessptr != NULL) - xfree(sessptr); + xfree(sessptr); return (NULL); } @@ -998,8 +993,7 @@ cmd_find_index(struct cmd_ctx *ctx, const char *arg, struct session **sp) } else if ((idx = cmd_lookup_index(s, winptr, &ambiguous)) == -1) goto invalid_index; - if (sessptr != NULL) - xfree(sessptr); + xfree(sessptr); return (idx); no_colon: @@ -1038,8 +1032,7 @@ no_session: ctx->error(ctx, "multiple sessions: %s", arg); else ctx->error(ctx, "session not found: %s", arg); - if (sessptr != NULL) - xfree(sessptr); + xfree(sessptr); return (-2); invalid_index: @@ -1047,8 +1040,7 @@ invalid_index: goto not_found; ctx->error(ctx, "invalid index: %s", arg); - if (sessptr != NULL) - xfree(sessptr); + xfree(sessptr); return (-2); not_found: @@ -1056,8 +1048,7 @@ not_found: ctx->error(ctx, "multiple windows: %s", arg); else ctx->error(ctx, "window not found: %s", arg); - if (sessptr != NULL) - xfree(sessptr); + xfree(sessptr); return (-2); } diff --git a/trunk/environ.c b/trunk/environ.c index 584b8de..3c88de9 100644 --- a/trunk/environ.c +++ b/trunk/environ.c @@ -52,8 +52,7 @@ environ_free(struct environ *env) envent = RB_ROOT(env); RB_REMOVE(environ, env, envent); xfree(envent->name); - if (envent->value != NULL) - xfree(envent->value); + xfree(envent->value); xfree(envent); } } @@ -85,8 +84,7 @@ environ_set(struct environ *env, const char *name, const char *value) struct environ_entry *envent; if ((envent = environ_find(env, name)) != NULL) { - if (envent->value != NULL) - xfree(envent->value); + xfree(envent->value); if (value != NULL) envent->value = xstrdup(value); else @@ -130,8 +128,7 @@ environ_unset(struct environ *env, const char *name) return; RB_REMOVE(environ, env, envent); xfree(envent->name); - if (envent->value != NULL) - xfree(envent->value); + xfree(envent->value); xfree(envent); } diff --git a/trunk/screen.c b/trunk/screen.c index 6f0f3e4..edd6f42 100644 --- a/trunk/screen.c +++ b/trunk/screen.c @@ -71,8 +71,7 @@ screen_reinit(struct screen *s) void screen_free(struct screen *s) { - if (s->tabs != NULL) - xfree(s->tabs); + xfree(s->tabs); xfree(s->title); xfree(s->ccolour); grid_destroy(s->grid); @@ -84,8 +83,7 @@ screen_reset_tabs(struct screen *s) { u_int i; - if (s->tabs != NULL) - xfree(s->tabs); + xfree(s->tabs); if ((s->tabs = bit_alloc(screen_size_x(s))) == NULL) fatal("bit_alloc failed"); diff --git a/trunk/server-client.c b/trunk/server-client.c index d1f7239..88e264a 100644 --- a/trunk/server-client.c +++ b/trunk/server-client.c @@ -147,16 +147,14 @@ server_client_lost(struct client *c) status_free_jobs(&c->status_old); screen_free(&c->status); - if (c->title != NULL) - xfree(c->title); + xfree(c->title); evtimer_del(&c->repeat_timer); if (event_initialized(&c->identify_timer)) evtimer_del(&c->identify_timer); - if (c->message_string != NULL) - xfree(c->message_string); + xfree(c->message_string); if (event_initialized (&c->message_timer)) evtimer_del(&c->message_timer); for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) { @@ -165,13 +163,9 @@ server_client_lost(struct client *c) } ARRAY_FREE(&c->message_log); - if (c->prompt_string != NULL) - xfree(c->prompt_string); - if (c->prompt_buffer != NULL) - xfree(c->prompt_buffer); - - if (c->cwd != NULL) - xfree(c->cwd); + xfree(c->prompt_string); + xfree(c->prompt_buffer); + xfree(c->cwd); environ_free(&c->environ); @@ -660,8 +654,7 @@ server_client_set_title(struct client *c) title = status_replace(c, NULL, NULL, NULL, template, time(NULL), 1); if (c->title == NULL || strcmp(title, c->title) != 0) { - if (c->title != NULL) - xfree(c->title); + xfree(c->title); c->title = xstrdup(title); tty_set_title(&c->tty, c->title); } diff --git a/trunk/session.c b/trunk/session.c index 0d3b8dd..1696d08 100644 --- a/trunk/session.c +++ b/trunk/session.c @@ -125,8 +125,7 @@ session_create(const char *name, const char *cmd, const char *cwd, s->name = NULL; do { s->idx = next_session++; - if (s->name != NULL) - xfree (s->name); + xfree (s->name); xasprintf(&s->name, "%u", s->idx); } while (RB_FIND(sessions, &sessions, s) != NULL); } @@ -156,8 +155,7 @@ session_destroy(struct session *s) RB_REMOVE(sessions, &sessions, s); notify_session_closed(s); - if (s->tio != NULL) - xfree(s->tio); + xfree(s->tio); session_group_remove(s); environ_free(&s->environ); diff --git a/trunk/status.c b/trunk/status.c index 2a419bb..2cba29b 100644 --- a/trunk/status.c +++ b/trunk/status.c @@ -222,8 +222,7 @@ status_redraw(struct client *c) /* Calculate the total size needed for the window list. */ wlstart = wloffset = wlwidth = 0; RB_FOREACH(wl, winlinks, &s->windows) { - if (wl->status_text != NULL) - xfree(wl->status_text); + xfree(wl->status_text); memcpy(&wl->status_cell, &stdgc, sizeof wl->status_cell); wl->status_text = status_print(c, wl, t, &wl->status_cell); wl->status_width = @@ -372,10 +371,8 @@ draw: screen_write_stop(&ctx); out: - if (left != NULL) - xfree(left); - if (right != NULL) - xfree(right); + xfree(left); + xfree(right); if (grid_compare(c->status.grid, old_status.grid) == 0) { screen_free(&old_status); @@ -491,8 +488,7 @@ do_replace: } out: - if (freeptr != NULL) - xfree(freeptr); + xfree(freeptr); return; skip_to: @@ -615,8 +611,7 @@ status_free_jobs(struct status_out_tree *sotree) so_next = RB_NEXT(status_out_tree, sotree, so); RB_REMOVE(status_out_tree, sotree, so); - if (so->out != NULL) - xfree(so->out); + xfree(so->out); xfree(so->cmd); xfree(so); } diff --git a/trunk/xmalloc.c b/trunk/xmalloc.c index 74262ed..7416088 100644 --- a/trunk/xmalloc.c +++ b/trunk/xmalloc.c @@ -85,8 +85,6 @@ xrealloc(void *oldptr, size_t nmemb, size_t size) void xfree(void *ptr) { - if (ptr == NULL) - fatalx("null pointer"); free(ptr); } -- 1.7.10 ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users