From 10e0aa77e9eb034f8a687e6dffc2e4e944ed30df Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 15 Apr 2024 08:19:55 +0000 Subject: [PATCH] Fixes for memory leaks reported by Lu Ming Yin, fixes from Howard Chu. --- usr.bin/tmux/arguments.c | 6 +++++- usr.bin/tmux/cmd-command-prompt.c | 3 ++- usr.bin/tmux/cmd-confirm-before.c | 6 ++++-- usr.bin/tmux/layout-custom.c | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c index 04b859fa19b..bff135ca0e6 100644 --- a/usr.bin/tmux/arguments.c +++ b/usr.bin/tmux/arguments.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arguments.c,v 1.62 2023/11/14 20:01:11 nicm Exp $ */ +/* $OpenBSD: arguments.c,v 1.63 2024/04/15 08:19:55 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott @@ -171,6 +171,8 @@ args_parse_flag_argument(struct args_value *values, u_int count, char **cause, if (optional_argument) { log_debug("%s: -%c (optional)", __func__, flag); args_set(args, flag, NULL, ARGS_ENTRY_OPTIONAL_VALUE); + args_free_value(new); + free(new); return (0); /* either - or end */ } xasprintf(cause, "-%c expects an argument", flag); @@ -662,6 +664,8 @@ args_set(struct args *args, u_char flag, struct args_value *value, int flags) entry->count++; if (value != NULL && value->type != ARGS_NONE) TAILQ_INSERT_TAIL(&entry->values, value, entry); + else + free(value); } /* Get argument value. Will be NULL if it isn't present. */ diff --git a/usr.bin/tmux/cmd-command-prompt.c b/usr.bin/tmux/cmd-command-prompt.c index 95e11eb3661..5d54357e5e8 100644 --- a/usr.bin/tmux/cmd-command-prompt.c +++ b/usr.bin/tmux/cmd-command-prompt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-command-prompt.c,v 1.66 2023/03/15 08:15:39 nicm Exp $ */ +/* $OpenBSD: cmd-command-prompt.c,v 1.67 2024/04/15 08:19:55 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -143,6 +143,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item) cdata->prompt_type = status_prompt_type(type); if (cdata->prompt_type == PROMPT_TYPE_INVALID) { cmdq_error(item, "unknown type: %s", type); + cmd_command_prompt_free(cdata); return (CMD_RETURN_ERROR); } } else diff --git a/usr.bin/tmux/cmd-confirm-before.c b/usr.bin/tmux/cmd-confirm-before.c index b4f665e5afd..8588170390f 100644 --- a/usr.bin/tmux/cmd-confirm-before.c +++ b/usr.bin/tmux/cmd-confirm-before.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-confirm-before.c,v 1.53 2023/04/28 06:12:27 nicm Exp $ */ +/* $OpenBSD: cmd-confirm-before.c,v 1.54 2024/04/15 08:19:55 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha @@ -76,8 +76,10 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) cdata = xcalloc(1, sizeof *cdata); cdata->cmdlist = args_make_commands_now(self, item, 0, 1); - if (cdata->cmdlist == NULL) + if (cdata->cmdlist == NULL) { + free(cdata); return (CMD_RETURN_ERROR); + } if (wait) cdata->item = item; diff --git a/usr.bin/tmux/layout-custom.c b/usr.bin/tmux/layout-custom.c index 1c1dd6b1488..2906e75908b 100644 --- a/usr.bin/tmux/layout-custom.c +++ b/usr.bin/tmux/layout-custom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: layout-custom.c,v 1.22 2023/02/02 09:24:59 nicm Exp $ */ +/* $OpenBSD: layout-custom.c,v 1.23 2024/04/15 08:19:55 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott @@ -230,7 +230,7 @@ layout_parse(struct window *w, const char *layout, char **cause) /* Check the new layout. */ if (!layout_check(lc)) { *cause = xstrdup("size mismatch after applying layout"); - return (-1); + goto fail; } /* Resize to the layout size. */ -- 2.20.1