Skip to content

Commit

Permalink
Sync OpenBSD patchset 1150:
Browse files Browse the repository at this point in the history
xfree is not particularly helpful, remove it. From Thomas Adam.
  • Loading branch information
Tiago Cunha committed Jul 11, 2012
1 parent 06d27e9 commit a432fcd
Show file tree
Hide file tree
Showing 73 changed files with 330 additions and 360 deletions.
20 changes: 8 additions & 12 deletions arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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. */
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 6 additions & 5 deletions cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "tmux.h"
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion client.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ client_connect(char *path, int start_server)
if (unlink(path) != 0 && errno != ENOENT)
return (-1);
fd = server_start(lockfd, lockfile);
xfree(lockfile);
free(lockfile);
close(lockfd);
}

Expand Down
4 changes: 3 additions & 1 deletion cmd-attach-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <sys/types.h>

#include <stdlib.h>

#include "tmux.h"

/*
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion cmd-bind-key.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <sys/types.h>

#include <stdlib.h>
#include <string.h>

#include "tmux.h"
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions cmd-break-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions cmd-capture-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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");
Expand All @@ -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);
}

Expand Down
11 changes: 6 additions & 5 deletions cmd-choose-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <sys/types.h>

#include <ctype.h>
#include <stdlib.h>

#include "tmux.h"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
9 changes: 5 additions & 4 deletions cmd-choose-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <sys/types.h>

#include <ctype.h>
#include <stdlib.h>

#include "tmux.h"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
12 changes: 6 additions & 6 deletions cmd-choose-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <sys/types.h>

#include <ctype.h>
#include <stdlib.h>

#include <string.h>

Expand Down Expand Up @@ -206,7 +207,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
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
Expand All @@ -215,8 +216,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
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);
Expand All @@ -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);

}

20 changes: 9 additions & 11 deletions cmd-command-prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <sys/types.h>

#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;

/*
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Loading

0 comments on commit a432fcd

Please sign in to comment.