Sync OpenBSD patchset 1150:

xfree is not particularly helpful, remove it. From Thomas Adam.
This commit is contained in:
Tiago Cunha 2012-07-11 19:34:16 +00:00
parent 06d27e94b2
commit a432fcd306
73 changed files with 330 additions and 360 deletions

View File

@ -68,15 +68,14 @@ args_parse(const char *template, int argc, char **argv)
if (opt < 0 || opt >= SCHAR_MAX)
continue;
if (opt == '?' || (ptr = strchr(template, opt)) == NULL) {
xfree(args->flags);
xfree(args);
free(args->flags);
free(args);
return (NULL);
}
bit_set(args->flags, opt);
if (ptr[1] == ':') {
if (args->values[opt] != NULL)
xfree(args->values[opt]);
free(args->values[opt]);
args->values[opt] = xstrdup(optarg);
}
}
@ -97,13 +96,11 @@ 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++)
free(args->values[i]);
xfree(args->flags);
xfree(args);
free(args->flags);
free(args);
}
/* Print a set of arguments. */
@ -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]);
free(args->values[ch]);
if (value != NULL)
args->values[ch] = xstrdup(value);
else

View File

@ -109,13 +109,12 @@
} while (0)
#define ARRAY_FREE(a) do { \
if ((a)->list != NULL) \
xfree((a)->list); \
free((a)->list); \
ARRAY_INIT(a); \
} while (0)
#define ARRAY_FREEALL(a) do { \
ARRAY_FREE(a); \
xfree(a); \
free(a); \
} while (0)
#endif

11
cfg.c
View File

@ -21,6 +21,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -117,14 +118,14 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
line = NULL;
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
xfree(buf);
free(buf);
if (cause == NULL)
continue;
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
xfree(cause);
free(cause);
continue;
} else
xfree(buf);
free(buf);
if (cmdlist == NULL)
continue;
cfg_cause = NULL;
@ -150,13 +151,13 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
if (cfg_cause != NULL) {
cfg_add_cause(
causes, "%s: %d: %s", path, n, cfg_cause);
xfree(cfg_cause);
free(cfg_cause);
}
}
if (line != NULL) {
cfg_add_cause(causes,
"%s: %d: line continuation at end of file", path, n);
xfree(line);
free(line);
}
fclose(f);

View File

@ -122,7 +122,7 @@ retry:
if (unlink(path) != 0 && errno != ENOENT)
return (-1);
fd = server_start(lockfd, lockfile);
xfree(lockfile);
free(lockfile);
close(lockfd);
}

View File

@ -18,6 +18,8 @@
#include <sys/types.h>
#include <stdlib.h>
#include "tmux.h"
/*
@ -81,7 +83,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
} else {
if (server_client_open(ctx->cmdclient, s, &cause) != 0) {
ctx->error(ctx, "open terminal failed: %s", cause);
xfree(cause);
free(cause);
return (-1);
}

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -74,7 +75,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, &cause);
if (cmdlist == NULL) {
ctx->error(ctx, "%s", cause);
xfree(cause);
free(cause);
return (-1);
}

View File

@ -81,7 +81,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
w->active = wp;
name = default_window_name(w);
window_set_name(w, name);
xfree(name);
free(name);
layout_init(w);
base_idx = options_get_number(&s->options, "base-index");
@ -106,7 +106,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cp = format_expand(ft, template);
ctx->print(ctx, "%s", cp);
xfree(cp);
free(cp);
format_free(ft);
}

View File

@ -62,7 +62,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
if (cause != NULL) {
top = gd->hsize;
xfree(cause);
free(cause);
} else if (n < 0 && (u_int) -n > gd->hsize)
top = 0;
else
@ -73,7 +73,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause);
if (cause != NULL) {
bottom = gd->hsize + gd->sy - 1;
xfree(cause);
free(cause);
} else if (n < 0 && (u_int) -n > gd->hsize)
bottom = 0;
else
@ -96,7 +96,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
len += linelen;
buf[len++] = '\n';
xfree(line);
free(line);
}
limit = options_get_number(&global_options, "buffer-limit");
@ -109,14 +109,14 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
xfree(buf);
xfree(cause);
free(buf);
free(cause);
return (-1);
}
if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
ctx->error(ctx, "no buffer %d", buffer);
xfree(buf);
free(buf);
return (-1);
}

View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include "tmux.h"
@ -86,11 +87,11 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
xasprintf(&action_data, "%u", idx - 1);
cdata->command = cmd_template_replace(action, action_data, 1);
xfree(action_data);
free(action_data);
window_choose_add(wl->window->active, cdata);
}
xfree(action);
free(action);
window_choose_ready(wl->window->active,
0, cmd_choose_buffer_callback, cmd_choose_buffer_free);
@ -119,7 +120,7 @@ cmd_choose_buffer_free(struct window_choose_data *data)
cdata->client->references--;
xfree(cdata->command);
xfree(cdata->ft_template);
xfree(cdata);
free(cdata->command);
free(cdata->ft_template);
free(cdata);
}

View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include "tmux.h"
@ -98,7 +99,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
window_choose_add(wl->window->active, cdata);
}
xfree(action);
free(action);
window_choose_ready(wl->window->active,
cur, cmd_choose_client_callback, cmd_choose_client_free);
@ -133,8 +134,8 @@ cmd_choose_client_free(struct window_choose_data *cdata)
cdata->client->references--;
xfree(cdata->ft_template);
xfree(cdata->command);
free(cdata->ft_template);
free(cdata->command);
format_free(cdata->ft);
xfree(cdata);
free(cdata);
}

View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@ -206,7 +207,7 @@ windows_only:
ctx, s2, wm, final_win_template,
final_win_action, idx_ses);
xfree(final_win_action);
free(final_win_action);
}
/*
* If we're just drawing windows, don't consider moving on to
@ -215,8 +216,7 @@ windows_only:
if (wflag && !sflag)
break;
}
if (final_win_template != NULL)
xfree(final_win_template);
free(final_win_template);
window_choose_ready(wl->window->active, cur_win,
cmd_choose_tree_callback, cmd_choose_tree_free);
@ -242,10 +242,10 @@ cmd_choose_tree_free(struct window_choose_data *cdata)
cdata->session->references--;
cdata->client->references--;
xfree(cdata->ft_template);
xfree(cdata->command);
free(cdata->ft_template);
free(cdata->command);
format_free(cdata->ft);
xfree(cdata);
free(cdata);
}

View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -138,7 +139,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
cmd_command_prompt_free, cdata, 0);
xfree(prompt);
free(prompt);
return (0);
}
@ -157,7 +158,7 @@ cmd_command_prompt_callback(void *data, const char *s)
return (0);
new_template = cmd_template_replace(cdata->template, s, cdata->idx);
xfree(cdata->template);
free(cdata->template);
cdata->template = new_template;
/*
@ -169,7 +170,7 @@ cmd_command_prompt_callback(void *data, const char *s)
input = strsep(&cdata->next_input, ",");
status_prompt_update(c, prompt, input);
xfree(prompt);
free(prompt);
cdata->idx++;
return (1);
}
@ -178,7 +179,7 @@ cmd_command_prompt_callback(void *data, const char *s)
if (cause != NULL) {
*cause = toupper((u_char) *cause);
status_message_set(c, "%s", cause);
xfree(cause);
free(cause);
}
return (0);
}
@ -205,11 +206,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);
free(cdata->inputs);
free(cdata->prompts);
free(cdata->template);
free(cdata);
}

View File

@ -17,6 +17,7 @@
*/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -87,7 +88,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
ptr = copy = xstrdup(args->argv[0]);
cmd = strsep(&ptr, " \t");
xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
xfree(copy);
free(copy);
}
cdata = xmalloc(sizeof *cdata);
@ -97,7 +98,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
PROMPT_SINGLE);
xfree(new_prompt);
free(new_prompt);
return (1);
}
@ -119,7 +120,7 @@ cmd_confirm_before_callback(void *data, const char *s)
if (cause != NULL) {
*cause = toupper((u_char) *cause);
status_message_set(c, "%s", cause);
xfree(cause);
free(cause);
}
return (0);
}
@ -144,7 +145,6 @@ cmd_confirm_before_free(void *data)
{
struct cmd_confirm_before_data *cdata = data;
if (cdata->cmd != NULL)
xfree(cdata->cmd);
xfree(cdata);
free(cdata->cmd);
free(cdata);
}

View File

@ -53,7 +53,7 @@ cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
xfree(cause);
free(cause);
return (-1);
}

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <time.h>
#include "tmux.h"
@ -93,7 +94,7 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
else
status_message_set(c, "%s", msg);
xfree(msg);
free(msg);
format_free(ft);
return (0);
}

View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <fnmatch.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -134,7 +135,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
xasprintf(&sctx,
"pane %u line %u: \"%s\"", i - 1,
line + 1, sres);
xfree(sres);
free(sres);
}
}
@ -143,7 +144,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
break;
}
}
xfree(searchstr);
free(searchstr);
if (ARRAY_LENGTH(&list_idx) == 0) {
ctx->error(ctx, "no windows matching: %s", str);
@ -217,7 +218,7 @@ cmd_find_window_free(struct window_choose_data *cdata)
cdata->session->references--;
xfree(cdata->ft_template);
free(cdata->ft_template);
format_free(cdata->ft);
xfree(cdata);
free(cdata);
}

View File

@ -20,6 +20,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -91,7 +92,7 @@ cmd_if_shell_callback(struct job *job)
if (cmd_string_parse(cmd, &cmdlist, &cause) != 0) {
if (cause != NULL) {
ctx->error(ctx, "%s", cause);
xfree(cause);
free(cause);
}
return;
}
@ -115,8 +116,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_if);
xfree(cdata);
free(cdata->cmd_else);
free(cdata->cmd_if);
free(cdata);
}

View File

@ -115,14 +115,14 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "size %s", cause);
xfree(cause);
free(cause);
return (-1);
}
} else if (args_has(args, 'p')) {
percentage = args_strtonum(args, 'p', 0, 100, &cause);
if (cause != NULL) {
ctx->error(ctx, "percentage %s", cause);
xfree(cause);
free(cause);
return (-1);
}
if (type == LAYOUT_TOPBOTTOM)

View File

@ -56,7 +56,7 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
dflag = args_has(self->args, 'd');
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
ctx->error(ctx, "can't link window: %s", cause);
xfree(cause);
free(cause);
return (-1);
}
recalculate_sizes();

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -60,7 +61,7 @@ cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx)
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
xfree(line);
free(line);
format_free(ft);
}

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -76,7 +77,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
xfree(line);
free(line);
format_free(ft);
}

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include "tmux.h"
@ -135,7 +136,7 @@ cmd_list_panes_window(struct cmd *self,
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
xfree(line);
free(line);
format_free(ft);
n++;

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -60,7 +61,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx)
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
xfree(line);
free(line);
format_free(ft);
n++;

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include "tmux.h"
@ -103,7 +104,7 @@ cmd_list_windows_session(
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
xfree(line);
free(line);
format_free(ft);
n++;

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -139,7 +140,7 @@ cmd_list_free(struct cmd_list *cmdlist)
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
cmd_free(cmd);
}
xfree(cmdlist);
free(cmdlist);
}
size_t

View File

@ -62,7 +62,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
xfree(cause);
free(cause);
return (-1);
}
}
@ -76,7 +76,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer_ptr, &cause);
if (error != 0) {
ctx->error(ctx, "%s: %s", path, cause);
xfree(cause);
free(cause);
return (-1);
}
return (1);
@ -127,15 +127,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
}
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
ctx->error(ctx, "no buffer %d", buffer);
xfree(pdata);
free(pdata);
return (-1);
}
return (0);
error:
if (pdata != NULL)
xfree(pdata);
free(pdata);
if (f != NULL)
fclose(f);
return (-1);
@ -158,7 +157,7 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
psize = EVBUFFER_LENGTH(c->stdin_data);
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL) {
xfree(data);
free(data);
return;
}
memcpy(pdata, EVBUFFER_DATA(c->stdin_data), psize);
@ -174,5 +173,5 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
server_push_stderr(c);
}
xfree(data);
free(data);
}

View File

@ -66,7 +66,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
dflag = args_has(self->args, 'd');
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
ctx->error(ctx, "can't move window: %s", cause);
xfree(cause);
free(cause);
return (-1);
}
server_unlink_window(src, wl);

View File

@ -130,7 +130,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if (!detached && ctx->cmdclient != NULL) {
if (server_client_open(ctx->cmdclient, NULL, &cause) != 0) {
ctx->error(ctx, "open terminal failed: %s", cause);
xfree(cause);
free(cause);
return (-1);
}
}
@ -201,7 +201,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
if (s == NULL) {
ctx->error(ctx, "create session failed: %s", cause);
xfree(cause);
free(cause);
return (-1);
}
environ_free(&env);
@ -264,7 +264,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
cause = ARRAY_ITEM(&cfg_causes, i);
window_copy_add(wp, "%s", cause);
xfree(cause);
free(cause);
}
ARRAY_FREE(&cfg_causes);
}

View File

@ -112,7 +112,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);
if (wl == NULL) {
ctx->error(ctx, "create window failed: %s", cause);
xfree(cause);
free(cause);
return (-1);
}
if (!detached) {
@ -134,7 +134,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cp = format_expand(ft, template);
ctx->print(ctx, "%s", cp);
xfree(cp);
free(cp);
format_free(ft);
}

View File

@ -63,7 +63,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
xfree(cause);
free(cause);
return (-1);
}
}

View File

@ -59,7 +59,7 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
RB_REMOVE(sessions, &sessions, s);
xfree(s->name);
free(s->name);
s->name = xstrdup(newname);
RB_INSERT(sessions, &sessions, s);

View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include "tmux.h"
@ -79,7 +80,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd = NULL;
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
ctx->error(ctx, "respawn pane failed: %s", cause);
xfree(cause);
free(cause);
environ_free(&env);
return (-1);
}

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include "tmux.h"
@ -81,7 +82,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd = NULL;
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
ctx->error(ctx, "respawn window failed: %s", cause);
xfree(cause);
free(cause);
environ_free(&env);
server_destroy_pane(wp);
return (-1);

View File

@ -20,6 +20,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -101,7 +102,7 @@ cmd_run_shell_callback(struct job *job)
ctx->print(ctx, "%s", line);
lines++;
xfree(line);
free(line);
}
cmd = cdata->cmd;
@ -119,7 +120,7 @@ cmd_run_shell_callback(struct job *job)
ctx->print(ctx, "%s", msg);
else
ctx->info(ctx, "%s", msg);
xfree(msg);
free(msg);
}
}
@ -136,6 +137,6 @@ cmd_run_shell_free(void *data)
if (ctx->curclient != NULL)
ctx->curclient->references--;
xfree(cdata->cmd);
xfree(cdata);
free(cdata->cmd);
free(cdata);
}

View File

@ -20,6 +20,7 @@
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -62,7 +63,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
xfree(cause);
free(cause);
return (-1);
}

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -60,14 +61,14 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
xfree(cause);
xfree(pdata);
free(cause);
free(pdata);
return (-1);
}
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
ctx->error(ctx, "no buffer %d", buffer);
xfree(pdata);
free(pdata);
return (-1);
}

View File

@ -257,7 +257,7 @@ cmd_set_option_string(struct cmd *self, unused struct cmd_ctx *ctx,
o = options_set_string(oo, oe->name, "%s", newval);
xfree(newval);
free(newval);
return (o);
}

View File

@ -18,6 +18,8 @@
#include <sys/types.h>
#include <stdlib.h>
#include "tmux.h"
/*
@ -59,7 +61,7 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
xfree(cause);
free(cause);
return (-1);
}
@ -101,9 +103,9 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buf[len] = '\0';
ctx->print(ctx, "%s", buf);
}
xfree(buf);
free(buf);
xfree(in);
free(in);
return (0);
}

View File

@ -18,6 +18,8 @@
#include <sys/types.h>
#include <stdlib.h>
#include "tmux.h"
/*
@ -59,13 +61,13 @@ cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
cause = ARRAY_ITEM(&causes, i);
window_copy_add(wp, "%s", cause);
xfree(cause);
free(cause);
}
} else {
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
cause = ARRAY_ITEM(&causes, i);
ctx->print(ctx, "%s", cause);
xfree(cause);
free(cause);
}
}
ARRAY_FREE(&causes);

View File

@ -93,7 +93,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
if (cause != NULL) {
xasprintf(&new_cause, "size %s", cause);
xfree(cause);
free(cause);
cause = new_cause;
goto error;
}
@ -101,7 +101,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
if (cause != NULL) {
xasprintf(&new_cause, "percentage %s", cause);
xfree(cause);
free(cause);
cause = new_cause;
goto error;
}
@ -150,7 +150,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cp = format_expand(ft, template);
ctx->print(ctx, "%s", cp);
xfree(cp);
free(cp);
format_free(ft);
}
@ -162,6 +162,6 @@ error:
if (new_wp != NULL)
window_remove_pane(w, new_wp);
ctx->error(ctx, "create pane failed: %s", cause);
xfree(cause);
free(cause);
return (-1);
}

View File

@ -87,7 +87,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
xfree(t);
free(t);
break;
case '"':
if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
@ -95,7 +95,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
xfree(t);
free(t);
break;
case '$':
if ((t = cmd_string_variable(s, &p)) == NULL)
@ -103,7 +103,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
xfree(t);
free(t);
break;
case '#':
/* Comment: discard rest of line. */
@ -152,7 +152,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
xfree(t);
free(t);
break;
}
/* FALLTHROUGH */
@ -170,13 +170,12 @@ error:
xasprintf(cause, "invalid or unknown command: %s", s);
out:
if (buf != NULL)
xfree(buf);
free(buf);
if (argv != NULL) {
for (i = 0; i < argc; i++)
xfree(argv[i]);
xfree(argv);
free(argv[i]);
free(argv);
}
return (rval);
@ -224,7 +223,7 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
xfree(t);
free(t);
continue;
}
@ -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);
free(buf);
return (NULL);
}
@ -303,14 +301,13 @@ cmd_string_variable(const char *s, size_t *p)
buf[len] = '\0';
envent = environ_find(&global_environ, buf);
xfree(buf);
free(buf);
if (envent == NULL)
return (xstrdup(""));
return (xstrdup(envent->value));
error:
if (buf != NULL)
xfree(buf);
free(buf);
return (NULL);
}
@ -334,7 +331,7 @@ cmd_string_expand_tilde(const char *s, size_t *p)
return (NULL);
if ((pw = getpwnam(username)) != NULL)
home = pw->pw_dir;
xfree(username);
free(username);
}
if (home == NULL)
return (NULL);

View File

@ -18,6 +18,8 @@
#include <sys/types.h>
#include <stdlib.h>
#include "tmux.h"
/*
@ -100,7 +102,7 @@ cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
while (!RB_EMPTY(mtab->tree)) {
mbind = RB_ROOT(mtab->tree);
RB_REMOVE(mode_key_tree, mtab->tree, mbind);
xfree(mbind);
free(mbind);
}
return (0);
}
@ -109,7 +111,7 @@ cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
mtmp.mode = !!args_has(args, 'c');
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
RB_REMOVE(mode_key_tree, mtab->tree, mbind);
xfree(mbind);
free(mbind);
}
return (0);
}

45
cmd.c
View File

@ -197,11 +197,9 @@ cmd_free_argv(int argc, char **argv)
if (argc == 0)
return;
for (i = 0; i < argc; i++) {
if (argv[i] != NULL)
xfree(argv[i]);
}
xfree(argv);
for (i = 0; i < argc; i++)
free(argv[i]);
free(argv);
}
struct cmd *
@ -290,9 +288,8 @@ cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx)
void
cmd_free(struct cmd *cmd)
{
if (cmd->args != NULL)
args_free(cmd->args);
xfree(cmd);
args_free(cmd->args);
free(cmd);
}
size_t
@ -506,7 +503,7 @@ cmd_find_client(struct cmd_ctx *ctx, const char *arg)
if (c == NULL)
ctx->error(ctx, "client not found: %s", tmparg);
xfree(tmparg);
free(tmparg);
return (c);
}
@ -766,7 +763,7 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
/* An empty session name is the current session. */
if (*tmparg == '\0') {
xfree(tmparg);
free(tmparg);
return (cmd_current_session(ctx, prefer_unattached));
}
@ -785,7 +782,7 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
ctx->error(ctx, "session not found: %s", tmparg);
}
xfree(tmparg);
free(tmparg);
return (s);
}
@ -860,7 +857,7 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
goto not_found;
if (sessptr != NULL)
xfree(sessptr);
free(sessptr);
return (wl);
no_colon:
@ -898,8 +895,7 @@ no_session:
ctx->error(ctx, "multiple sessions: %s", arg);
else
ctx->error(ctx, "session not found: %s", arg);
if (sessptr != NULL)
xfree(sessptr);
free(sessptr);
return (NULL);
not_found:
@ -907,8 +903,7 @@ not_found:
ctx->error(ctx, "multiple windows: %s", arg);
else
ctx->error(ctx, "window not found: %s", arg);
if (sessptr != NULL)
xfree(sessptr);
free(sessptr);
return (NULL);
}
@ -999,8 +994,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);
free(sessptr);
return (idx);
no_colon:
@ -1039,8 +1033,7 @@ no_session:
ctx->error(ctx, "multiple sessions: %s", arg);
else
ctx->error(ctx, "session not found: %s", arg);
if (sessptr != NULL)
xfree(sessptr);
free(sessptr);
return (-2);
invalid_index:
@ -1048,8 +1041,7 @@ invalid_index:
goto not_found;
ctx->error(ctx, "invalid index: %s", arg);
if (sessptr != NULL)
xfree(sessptr);
free(sessptr);
return (-2);
not_found:
@ -1057,8 +1049,7 @@ not_found:
ctx->error(ctx, "multiple windows: %s", arg);
else
ctx->error(ctx, "window not found: %s", arg);
if (sessptr != NULL)
xfree(sessptr);
free(sessptr);
return (-2);
}
@ -1152,7 +1143,7 @@ cmd_find_pane(struct cmd_ctx *ctx,
goto lookup_string;
}
xfree(winptr);
free(winptr);
return (wl);
lookup_string:
@ -1162,7 +1153,7 @@ lookup_string:
goto error;
}
xfree(winptr);
free(winptr);
return (wl);
no_period:
@ -1188,7 +1179,7 @@ lookup_window:
return (wl);
error:
xfree(winptr);
free(winptr);
return (NULL);
}

View File

@ -20,6 +20,7 @@
#include <sys/types.h>
#include <event.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -110,12 +111,12 @@ control_callback(struct client *c, int closed, unused void *data)
if (cmd_string_parse(line, &cmdlist, &cause) != 0) {
control_write(c, "%%error in line \"%s\": %s", line,
cause);
xfree(cause);
free(cause);
} else {
cmd_list_exec(cmdlist, &ctx);
cmd_list_free(cmdlist);
}
xfree(line);
free(line);
}
}

View File

@ -51,10 +51,9 @@ environ_free(struct environ *env)
while (!RB_EMPTY(env)) {
envent = RB_ROOT(env);
RB_REMOVE(environ, env, envent);
xfree(envent->name);
if (envent->value != NULL)
xfree(envent->value);
xfree(envent);
free(envent->name);
free(envent->value);
free(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);
free(envent->value);
if (value != NULL)
envent->value = xstrdup(value);
else
@ -117,7 +115,7 @@ environ_put(struct environ *env, const char *var)
name[strcspn(name, "=")] = '\0';
environ_set(env, name, value);
xfree(name);
free(name);
}
/* Unset an environment variable. */
@ -129,10 +127,9 @@ environ_unset(struct environ *env, const char *name)
if ((envent = environ_find(env, name)) == NULL)
return;
RB_REMOVE(environ, env, envent);
xfree(envent->name);
if (envent->value != NULL)
xfree(envent->value);
xfree(envent);
free(envent->name);
free(envent->value);
free(envent);
}
/*
@ -152,7 +149,7 @@ environ_update(const char *vars, struct environ *srcenv, struct environ *dstenv)
else
environ_set(dstenv, envent->name, envent->value);
}
xfree(copyvars);
free(copyvars);
}
/* Push environment into the real environment - use after fork(). */

View File

@ -20,6 +20,7 @@
#include <netdb.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
@ -102,12 +103,12 @@ format_free(struct format_tree *ft)
fe_next = RB_NEXT(format_tree, ft, fe);
RB_REMOVE(format_tree, ft, fe);
xfree(fe->value);
xfree(fe->key);
xfree(fe);
free(fe->value);
free(fe->key);
free(fe);
}
xfree (ft);
free (ft);
}
/* Add a key-value pair. */
@ -195,11 +196,11 @@ format_replace(struct format_tree *ft,
memcpy(*buf + *off, value, valuelen);
*off += valuelen;
xfree(copy);
free(copy);
return (0);
fail:
xfree(copy);
free(copy);
return (-1);
}
@ -351,8 +352,8 @@ format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
format_add(ft, "window_active", "%d", wl == s->curw);
format_add(ft, "window_panes", "%u", window_count_panes(w));
xfree(flags);
xfree(layout);
free(flags);
free(layout);
}
/* Set default format keys for a window pane. */
@ -403,5 +404,5 @@ format_paste_buffer(struct format_tree *ft, struct paste_buffer *pb)
format_add(ft, "buffer_size", "%zu", pb->size);
format_add(ft, "buffer_sample", "%s", pb_print);
xfree(pb_print);
free(pb_print);
}

17
grid.c
View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -98,15 +99,13 @@ grid_destroy(struct grid *gd)
for (yy = 0; yy < gd->hsize + gd->sy; yy++) {
gl = &gd->linedata[yy];
if (gl->celldata != NULL)
xfree(gl->celldata);
if (gl->utf8data != NULL)
xfree(gl->utf8data);
free(gl->celldata);
free(gl->utf8data);
}
xfree(gd->linedata);
free(gd->linedata);
xfree(gd);
free(gd);
}
/* Compare grids. */
@ -373,10 +372,8 @@ grid_clear_lines(struct grid *gd, u_int py, u_int ny)
for (yy = py; yy < py + ny; yy++) {
gl = &gd->linedata[yy];
if (gl->celldata != NULL)
xfree(gl->celldata);
if (gl->utf8data != NULL)
xfree(gl->utf8data);
free(gl->celldata);
free(gl->utf8data);
memset(gl, 0, sizeof *gl);
}
}

View File

@ -163,7 +163,7 @@ input_key(struct window_pane *wp, int key)
if (options_get_number(&wp->window->options, "xterm-keys")) {
if ((out = xterm_keys_lookup(key)) != NULL) {
bufferevent_write(wp->event, out, strlen(out));
xfree(out);
free(out);
return;
}
}

View File

@ -853,7 +853,7 @@ input_reply(struct input_ctx *ictx, const char *fmt, ...)
va_end(ap);
bufferevent_write(ictx->wp->event, reply, strlen(reply));
xfree(reply);
free(reply);
}
/* Clear saved state. */

5
job.c
View File

@ -20,6 +20,7 @@
#include <sys/socket.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -116,7 +117,7 @@ job_free(struct job *job)
log_debug("free job %p: %s", job, job->cmd);
LIST_REMOVE(job, lentry);
xfree(job->cmd);
free(job->cmd);
if (job->freefn != NULL && job->data != NULL)
job->freefn(job->data);
@ -128,7 +129,7 @@ job_free(struct job *job)
if (job->fd != -1)
close(job->fd);
xfree(job);
free(job);
}
/* Job buffer error callback. */

View File

@ -90,7 +90,7 @@ key_bindings_clean(void)
bd = RB_ROOT(&dead_key_bindings);
RB_REMOVE(key_bindings, &dead_key_bindings, bd);
cmd_list_free(bd->cmdlist);
xfree(bd);
free(bd);
}
}
@ -216,7 +216,7 @@ key_bindings_error(struct cmd_ctx *ctx, const char *fmt, ...)
*msg = toupper((u_char) *msg);
status_message_set(ctx->curclient, "%s", msg);
xfree(msg);
free(msg);
}
void printflike2
@ -258,7 +258,7 @@ key_bindings_info(struct cmd_ctx *ctx, const char *fmt, ...)
*msg = toupper((u_char) *msg);
status_message_set(ctx->curclient, "%s", msg);
xfree(msg);
free(msg);
}
void

View File

@ -78,7 +78,7 @@ layout_free_cell(struct layout_cell *lc)
break;
}
xfree(lc);
free(lc);
}
void
@ -781,8 +781,8 @@ layout_list_add(struct window *w)
TAILQ_REMOVE(&w->layout_list, ll, entry);
w->layout_list_size--;
xfree(ll->layout);
xfree(ll);
free(ll->layout);
free(ll);
}
}

View File

@ -20,6 +20,7 @@
#include <ctype.h>
#include <libgen.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -73,12 +74,12 @@ window_name_callback(unused int fd, unused short events, void *data)
wname = parse_window_name(name + 1);
else
wname = parse_window_name(name);
xfree(name);
free(name);
}
if (w->active->fd == -1) {
xasprintf(&name, "%s[dead]", wname);
xfree(wname);
free(wname);
wname = name;
}
@ -86,7 +87,7 @@ window_name_callback(unused int fd, unused short events, void *data)
window_set_name(w, wname);
server_status_window(w);
}
xfree(wname);
free(wname);
}
char *
@ -122,6 +123,6 @@ parse_window_name(const char *in)
if (*name == '/')
name = basename(name);
name = xstrdup(name);
xfree(copy);
free(copy);
return (name);
}

View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -51,10 +52,10 @@ options_free(struct options *oo)
while (!RB_EMPTY(&oo->tree)) {
o = RB_ROOT(&oo->tree);
RB_REMOVE(options_tree, &oo->tree, o);
xfree(o->name);
free(o->name);
if (o->type == OPTIONS_STRING)
xfree(o->str);
xfree(o);
free(o->str);
free(o);
}
}
@ -92,10 +93,10 @@ options_remove(struct options *oo, const char *name)
return;
RB_REMOVE(options_tree, &oo->tree, o);
xfree(o->name);
free(o->name);
if (o->type == OPTIONS_STRING)
xfree(o->str);
xfree(o);
free(o->str);
free(o);
}
struct options_entry *printflike3
@ -109,7 +110,7 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...)
o->name = xstrdup(name);
RB_INSERT(options_tree, &oo->tree, o);
} else if (o->type == OPTIONS_STRING)
xfree(o->str);
free(o->str);
va_start(ap, fmt);
o->type = OPTIONS_STRING;
@ -140,7 +141,7 @@ options_set_number(struct options *oo, const char *name, long long value)
o->name = xstrdup(name);
RB_INSERT(options_tree, &oo->tree, o);
} else if (o->type == OPTIONS_STRING)
xfree(o->str);
free(o->str);
o->type = OPTIONS_NUMBER;
o->num = value;

15
paste.c
View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -69,8 +70,8 @@ paste_free_top(struct paste_stack *ps)
pb = ARRAY_FIRST(ps);
ARRAY_REMOVE(ps, 0);
xfree(pb->data);
xfree(pb);
free(pb->data);
free(pb);
return (0);
}
@ -87,8 +88,8 @@ paste_free_index(struct paste_stack *ps, u_int idx)
pb = ARRAY_ITEM(ps, idx);
ARRAY_REMOVE(ps, idx);
xfree(pb->data);
xfree(pb);
free(pb->data);
free(pb);
return (0);
}
@ -107,8 +108,8 @@ paste_add(struct paste_stack *ps, char *data, size_t size, u_int limit)
while (ARRAY_LENGTH(ps) >= limit) {
pb = ARRAY_LAST(ps);
xfree(pb->data);
xfree(pb);
free(pb->data);
free(pb);
ARRAY_TRUNC(ps, 1);
}
@ -136,7 +137,7 @@ paste_replace(struct paste_stack *ps, u_int idx, char *data, size_t size)
return (-1);
pb = ARRAY_ITEM(ps, idx);
xfree(pb->data);
free(pb->data);
pb->data = data;
pb->size = size;

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -102,8 +103,8 @@ screen_write_cstrlen(int utf8flag, const char *fmt, ...)
size = screen_write_strlen(utf8flag, "%s", msg2);
xfree(msg);
xfree(msg2);
free(msg);
free(msg2);
return (size);
}
@ -141,7 +142,7 @@ screen_write_strlen(int utf8flag, const char *fmt, ...)
}
}
xfree(msg);
free(msg);
return (size);
}
@ -215,7 +216,7 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
}
}
xfree(msg);
free(msg);
}
/* Write string, similar to nputs, but with embedded formatting (#[]). */
@ -285,7 +286,7 @@ screen_write_cnputs(struct screen_write_ctx *ctx,
}
}
xfree(msg);
free(msg);
}
/* Parse an embedded style of the form "fg=colour,bg=colour,bright,...". */

View File

@ -71,10 +71,9 @@ screen_reinit(struct screen *s)
void
screen_free(struct screen *s)
{
if (s->tabs != NULL)
xfree(s->tabs);
xfree(s->title);
xfree(s->ccolour);
free(s->tabs);
free(s->title);
free(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);
free(s->tabs);
if ((s->tabs = bit_alloc(screen_size_x(s))) == NULL)
fatal("bit_alloc failed");
@ -105,7 +103,7 @@ screen_set_cursor_style(struct screen *s, u_int style)
void
screen_set_cursor_colour(struct screen *s, const char *colour_string)
{
xfree(s->ccolour);
free(s->ccolour);
s->ccolour = xstrdup(colour_string);
}
@ -117,7 +115,7 @@ screen_set_title(struct screen *s, const char *title)
strlcpy(tmp, title, sizeof tmp);
xfree(s->title);
free(s->title);
s->title = xstrdup(tmp);
}

View File

@ -20,6 +20,7 @@
#include <event.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
@ -150,31 +151,25 @@ server_client_lost(struct client *c)
status_free_jobs(&c->status_old);
screen_free(&c->status);
if (c->title != NULL)
xfree(c->title);
free(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);
free(c->message_string);
if (event_initialized (&c->message_timer))
evtimer_del(&c->message_timer);
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
msg = &ARRAY_ITEM(&c->message_log, i);
xfree(msg->msg);
free(msg->msg);
}
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);
free(c->prompt_string);
free(c->prompt_buffer);
free(c->cwd);
environ_free(&c->environ);
@ -661,12 +656,11 @@ 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);
free(c->title);
c->title = xstrdup(title);
tty_set_title(&c->tty, c->title);
}
xfree(title);
free(title);
}
/* Dispatch message from client. */

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
@ -393,7 +394,7 @@ server_destroy_session_group(struct session *s)
TAILQ_FOREACH(s, &sg->sessions, gentry)
server_destroy_session(s);
TAILQ_REMOVE(&session_groups, sg, entry);
xfree(sg);
free(sg);
}
}

View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <event.h>
#include <stdlib.h>
#include <unistd.h>
#include "tmux.h"
@ -211,7 +212,7 @@ server_window_check_content(
return (0);
if ((found = window_pane_search(wp, ptr, NULL)) == NULL)
return (0);
xfree(found);
free(found);
if (options_get_number(&s->options, "bell-on-alert"))
ring_bell(s);

View File

@ -163,7 +163,7 @@ server_start(int lockfd, char *lockfile)
server_client_create(pair[1]);
unlink(lockfile);
xfree(lockfile);
free(lockfile);
close(lockfd);
if (access(SYSTEM_CFG, R_OK) == 0)
@ -186,7 +186,7 @@ server_start(int lockfd, char *lockfile)
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
cause = ARRAY_ITEM(&cfg_causes, i);
window_copy_add(wp, "%s", cause);
xfree(cause);
free(cause);
}
ARRAY_FREE(&cfg_causes);
}
@ -276,8 +276,8 @@ server_clean_dead(void)
next_s = RB_NEXT(sessions, &dead_sessions, s);
if (s->references == 0) {
RB_REMOVE(sessions, &dead_sessions, s);
xfree(s->name);
xfree(s);
free(s->name);
free(s);
}
s = next_s;
}
@ -287,7 +287,7 @@ server_clean_dead(void)
if (c == NULL || c->references != 0)
continue;
ARRAY_SET(&dead_clients, i, NULL);
xfree(c);
free(c);
}
}

View File

@ -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);
free (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);
free(s->tio);
session_group_remove(s);
environ_free(&s->environ);
@ -171,7 +169,7 @@ session_destroy(struct session *s)
winlink_remove(&s->windows, wl);
}
xfree(s->cwd);
free(s->cwd);
RB_INSERT(sessions, &dead_sessions, s);
}
@ -494,7 +492,7 @@ session_group_remove(struct session *s)
TAILQ_REMOVE(&sg->sessions, TAILQ_FIRST(&sg->sessions), gentry);
if (TAILQ_EMPTY(&sg->sessions)) {
TAILQ_REMOVE(&session_groups, sg, entry);
xfree(sg);
free(sg);
}
}

View File

@ -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);
free(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);
free(left);
free(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);
free(freeptr);
return;
skip_to:
@ -572,7 +568,7 @@ status_find_job(struct client *c, char **iptr)
cmd[len++] = **iptr;
}
if (**iptr == '\0') /* no terminating ) */ {
xfree(cmd);
free(cmd);
return (NULL);
}
(*iptr)++; /* skip final ) */
@ -582,7 +578,7 @@ status_find_job(struct client *c, char **iptr)
so_find.cmd = cmd;
so = RB_FIND(status_out_tree, &c->status_new, &so_find);
if (so != NULL && so->out != NULL) {
xfree(cmd);
free(cmd);
return (so->out);
}
@ -600,7 +596,7 @@ status_find_job(struct client *c, char **iptr)
/* Lookup in the old tree. */
so_find.cmd = cmd;
so = RB_FIND(status_out_tree, &c->status_old, &so_find);
xfree(cmd);
free(cmd);
if (so != NULL)
return (so->out);
return (NULL);
@ -618,10 +614,9 @@ 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->cmd);
xfree(so);
free(so->out);
free(so->cmd);
free(so);
}
}
@ -778,7 +773,7 @@ status_message_set(struct client *c, const char *fmt, ...)
limit = ARRAY_LENGTH(&c->message_log) - limit;
for (i = 0; i < limit; i++) {
msg = &ARRAY_FIRST(&c->message_log);
xfree(msg->msg);
free(msg->msg);
ARRAY_REMOVE(&c->message_log, 0);
}
}
@ -803,7 +798,7 @@ status_message_clear(struct client *c)
if (c->message_string == NULL)
return;
xfree(c->message_string);
free(c->message_string);
c->message_string = NULL;
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
@ -912,10 +907,10 @@ status_prompt_clear(struct client *c)
if (c->prompt_freefn != NULL && c->prompt_data != NULL)
c->prompt_freefn(c->prompt_data);
xfree(c->prompt_string);
free(c->prompt_string);
c->prompt_string = NULL;
xfree(c->prompt_buffer);
free(c->prompt_buffer);
c->prompt_buffer = NULL;
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
@ -928,11 +923,11 @@ status_prompt_clear(struct client *c)
void
status_prompt_update(struct client *c, const char *msg, const char *input)
{
xfree(c->prompt_string);
free(c->prompt_string);
c->prompt_string = status_replace(c, NULL, NULL, NULL, msg,
time(NULL), 0);
xfree(c->prompt_buffer);
free(c->prompt_buffer);
c->prompt_buffer = status_replace(c, NULL, NULL, NULL, input,
time(NULL), 0);
c->prompt_index = strlen(c->prompt_buffer);
@ -1109,7 +1104,7 @@ status_prompt_key(struct client *c, int key)
memcpy(first, s, strlen(s));
c->prompt_index = (first - c->prompt_buffer) + strlen(s);
xfree(s);
free(s);
c->flags |= CLIENT_STATUS;
break;
@ -1250,7 +1245,7 @@ status_prompt_key(struct client *c, int key)
histstr = status_prompt_up_history(&c->prompt_hindex);
if (histstr == NULL)
break;
xfree(c->prompt_buffer);
free(c->prompt_buffer);
c->prompt_buffer = xstrdup(histstr);
c->prompt_index = strlen(c->prompt_buffer);
c->flags |= CLIENT_STATUS;
@ -1259,7 +1254,7 @@ status_prompt_key(struct client *c, int key)
histstr = status_prompt_down_history(&c->prompt_hindex);
if (histstr == NULL)
break;
xfree(c->prompt_buffer);
free(c->prompt_buffer);
c->prompt_buffer = xstrdup(histstr);
c->prompt_index = strlen(c->prompt_buffer);
c->flags |= CLIENT_STATUS;
@ -1383,7 +1378,7 @@ status_prompt_add_history(const char *line)
return;
if (size == PROMPT_HISTORY) {
xfree(ARRAY_FIRST(&status_prompt_history));
free(ARRAY_FIRST(&status_prompt_history));
ARRAY_REMOVE(&status_prompt_history, 0);
}

21
tmux.c
View File

@ -76,7 +76,7 @@ logfile(const char *name)
if (debug_level > 0) {
xasprintf(&path, "tmux-%s-%ld.log", name, (long) getpid());
log_open(debug_level, path);
xfree(path);
free(path);
}
}
@ -255,8 +255,7 @@ main(int argc, char **argv)
flags &= ~IDENTIFY_256COLOURS;
break;
case 'c':
if (shell_cmd != NULL)
xfree(shell_cmd);
free(shell_cmd);
shell_cmd = xstrdup(optarg);
break;
case 'C':
@ -269,24 +268,21 @@ main(int argc, char **argv)
printf("%s %s\n", __progname, VERSION);
exit(0);
case 'f':
if (cfg_file != NULL)
xfree(cfg_file);
free(cfg_file);
cfg_file = xstrdup(optarg);
break;
case 'l':
login_shell = 1;
break;
case 'L':
if (label != NULL)
xfree(label);
free(label);
label = xstrdup(optarg);
break;
case 'q':
quiet = 1;
break;
case 'S':
if (path != NULL)
xfree(path);
free(path);
path = xstrdup(optarg);
break;
case 'u':
@ -366,7 +362,7 @@ main(int argc, char **argv)
}
xasprintf(&cfg_file, "%s/%s", home, DEFAULT_CFG);
if (access(cfg_file, R_OK) != 0 && errno == ENOENT) {
xfree(cfg_file);
free(cfg_file);
cfg_file = NULL;
}
}
@ -393,11 +389,10 @@ main(int argc, char **argv)
}
}
}
if (label != NULL)
xfree(label);
free(label);
if (realpath(path, socket_path) == NULL)
strlcpy(socket_path, path, sizeof socket_path);
xfree(path);
free(path);
#ifdef HAVE_SETPROCTITLE
/* Set process title. */

1
tmux.h
View File

@ -2221,7 +2221,6 @@ char *xstrdup(const char *);
void *xcalloc(size_t, size_t);
void *xmalloc(size_t);
void *xrealloc(void *, size_t, size_t);
void xfree(void *);
int printflike2 xasprintf(char **, const char *, ...);
int xvasprintf(char **, const char *, va_list);
int printflike3 xsnprintf(char *, size_t, const char *, ...);

View File

@ -384,7 +384,7 @@ tty_keys_free1(struct tty_key *tk)
tty_keys_free1(tk->left);
if (tk->right != NULL)
tty_keys_free1(tk->right);
xfree(tk);
free(tk);
}
/* Lookup a key in the tree. */

View File

@ -255,7 +255,7 @@ tty_term_override(struct tty_term *term, const char *overrides)
*ptr++ = '\0';
val = xstrdup(ptr);
if (strunvis(val, ptr) == -1) {
xfree(val);
free(val);
val = xstrdup(ptr);
}
} else if (entstr[strlen(entstr) - 1] == '@') {
@ -281,7 +281,7 @@ tty_term_override(struct tty_term *term, const char *overrides)
break;
case TTYCODE_STRING:
if (code->type == TTYCODE_STRING)
xfree(code->value.string);
free(code->value.string);
code->value.string = xstrdup(val);
code->type = ent->type;
break;
@ -299,12 +299,11 @@ tty_term_override(struct tty_term *term, const char *overrides)
}
}
if (val != NULL)
xfree(val);
free(val);
}
}
xfree(s);
free(s);
}
struct tty_term *
@ -468,10 +467,10 @@ tty_term_free(struct tty_term *term)
for (i = 0; i < NTTYCODE; i++) {
if (term->codes[i].type == TTYCODE_STRING)
xfree(term->codes[i].value.string);
free(term->codes[i].value.string);
}
xfree(term->name);
xfree(term);
free(term->name);
free(term);
}
int

10
tty.c
View File

@ -345,11 +345,11 @@ tty_free(struct tty *tty)
{
tty_close(tty);
xfree(tty->ccolour);
free(tty->ccolour);
if (tty->path != NULL)
xfree(tty->path);
free(tty->path);
if (tty->termname != NULL)
xfree(tty->termname);
free(tty->termname);
}
void
@ -468,7 +468,7 @@ tty_force_cursor_colour(struct tty *tty, const char *ccolour)
tty_putcode(tty, TTYC_CR);
else
tty_putcode_ptr1(tty, TTYC_CC, ccolour);
xfree(tty->ccolour);
free(tty->ccolour);
tty->ccolour = xstrdup(ccolour);
}
@ -1099,7 +1099,7 @@ tty_cmd_setselection(struct tty *tty, const struct tty_ctx *ctx)
b64_ntop(ctx->ptr, ctx->num, buf, off);
tty_putcode_ptr2(tty, TTYC_MS, "", buf);
xfree(buf);
free(buf);
}
void

View File

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@ -152,12 +153,12 @@ window_choose_free(struct window_pane *wp)
item = &ARRAY_ITEM(&data->list, i);
if (data->freefn != NULL && item->wcd != NULL)
data->freefn(item->wcd);
xfree(item->name);
free(item->name);
}
ARRAY_FREE(&data->list);
screen_free(&data->screen);
xfree(data);
free(data);
}
void
@ -493,7 +494,7 @@ window_choose_ctx(struct window_choose_data *cdata)
if (cause != NULL) {
*cause = toupper((u_char) *cause);
status_message_set(cdata->client, "%s", cause);
xfree(cause);
free(cause);
}
return;
}
@ -544,7 +545,7 @@ window_choose_add_window(struct window_pane *wp, struct cmd_ctx *ctx,
xasprintf(&action_data, "%s:%d", s->name, wl->idx);
wcd->command = cmd_template_replace(action, action_data, 1);
xfree(action_data);
free(action_data);
wcd->idx = wl->idx;
wcd->ft_template = xstrdup(template);

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -69,7 +70,7 @@ window_clock_free(struct window_pane *wp)
struct window_clock_mode_data *data = wp->modedata;
screen_free(&data->screen);
xfree(data);
free(data);
}
void

View File

@ -240,17 +240,16 @@ window_copy_free(struct window_pane *wp)
if (wp->fd != -1)
bufferevent_enable(wp->event, EV_READ|EV_WRITE);
if (data->searchstr != NULL)
xfree(data->searchstr);
xfree(data->inputstr);
free(data->searchstr);
free(data->inputstr);
if (data->backing != &wp->base) {
screen_free(data->backing);
xfree(data->backing);
free(data->backing);
}
screen_free(&data->screen);
xfree(data);
free(data);
}
void
@ -1379,7 +1378,7 @@ window_copy_copy_selection(struct window_pane *wp, int idx)
/* Don't bother if no data. */
if (off == 0) {
xfree(buf);
free(buf);
return;
}
off--; /* remove final \n */

View File

@ -176,9 +176,8 @@ winlink_remove(struct winlinks *wwl, struct winlink *wl)
struct window *w = wl->window;
RB_REMOVE(winlinks, wwl, wl);
if (wl->status_text != NULL)
xfree(wl->status_text);
xfree(wl);
free(wl->status_text);
free(wl);
if (w != NULL) {
if (w->references == 0)
@ -356,16 +355,14 @@ window_destroy(struct window *w)
window_destroy_panes(w);
if (w->name != NULL)
xfree(w->name);
xfree(w);
free(w->name);
free(w);
}
void
window_set_name(struct window *w, const char *new_name)
{
if (w->name != NULL)
xfree(w->name);
free(w->name);
w->name = xstrdup(new_name);
notify_window_renamed(w);
}
@ -668,13 +665,10 @@ window_pane_destroy(struct window_pane *wp)
RB_REMOVE(window_pane_tree, &all_window_panes, wp);
if (wp->cwd != NULL)
xfree(wp->cwd);
if (wp->shell != NULL)
xfree(wp->shell);
if (wp->cmd != NULL)
xfree(wp->cmd);
xfree(wp);
free(wp->cwd);
free(wp->shell);
free(wp->cmd);
free(wp);
}
int
@ -691,18 +685,15 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
close(wp->fd);
}
if (cmd != NULL) {
if (wp->cmd != NULL)
xfree(wp->cmd);
free(wp->cmd);
wp->cmd = xstrdup(cmd);
}
if (shell != NULL) {
if (wp->shell != NULL)
xfree(wp->shell);
free(wp->shell);
wp->shell = xstrdup(shell);
}
if (cwd != NULL) {
if (wp->cwd != NULL)
xfree(wp->cwd);
free(wp->cwd);
wp->cwd = xstrdup(cwd);
}
@ -1058,10 +1049,10 @@ window_pane_search(struct window_pane *wp, const char *searchstr, u_int *lineno)
*lineno = i;
break;
}
xfree(line);
free(line);
}
xfree(newsearchstr);
free(newsearchstr);
return (msg);
}

View File

@ -82,14 +82,6 @@ xrealloc(void *oldptr, size_t nmemb, size_t size)
return (newptr);
}
void
xfree(void *ptr)
{
if (ptr == NULL)
fatalx("null pointer");
free(ptr);
}
int printflike2
xasprintf(char **ret, const char *fmt, ...)
{