diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-05-15 08:39:31 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-05-15 08:39:31 +0000 |
commit | 339e9e029df38fb819af375b42cddc8f70920520 (patch) | |
tree | d9dcf883dc66598f9d224ba532bc887714b887d8 /usr.bin/tmux | |
parent | 24db68c4824e3f1780dfbe3a0fa0ec8a873cb619 (diff) |
Fix memory leaks reported by Lu Ming Yin.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/cmd-confirm-before.c | 7 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 42 |
2 files changed, 25 insertions, 24 deletions
diff --git a/usr.bin/tmux/cmd-confirm-before.c b/usr.bin/tmux/cmd-confirm-before.c index 8588170390f..fd858876b8a 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.54 2024/04/15 08:19:55 nicm Exp $ */ +/* $OpenBSD: cmd-confirm-before.c,v 1.55 2024/05/15 08:39:30 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -92,6 +92,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) cdata->confirm_key = confirm_key[0]; else { cmdq_error(item, "invalid confirm key"); + free(cdata); return (CMD_RETURN_ERROR); } } @@ -102,8 +103,8 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) xasprintf(&new_prompt, "%s ", prompt); else { cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name; - xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ", - cmd, cdata->confirm_key); + xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ", cmd, + cdata->confirm_key); } status_prompt_set(tc, target, new_prompt, NULL, diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 1f2138bca20..5c75db37aeb 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.241 2023/11/14 15:59:49 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.242 2024/05/15 08:39:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -994,8 +994,7 @@ status_prompt_paste(struct client *c) if ((pb = paste_get_top(NULL)) == NULL) return (0); bufdata = paste_buffer_data(pb, &bufsize); - ud = xreallocarray(NULL, bufsize + 1, sizeof *ud); - udp = ud; + ud = udp = xreallocarray(NULL, bufsize + 1, sizeof *ud); for (i = 0; i != bufsize; /* nothing */) { more = utf8_open(udp, bufdata[i]); if (more == UTF8_MORE) { @@ -1016,25 +1015,24 @@ status_prompt_paste(struct client *c) udp->size = 0; n = udp - ud; } - if (n == 0) - return (0); - - c->prompt_buffer = xreallocarray(c->prompt_buffer, size + n + 1, - sizeof *c->prompt_buffer); - if (c->prompt_index == size) { - memcpy(c->prompt_buffer + c->prompt_index, ud, - n * sizeof *c->prompt_buffer); - c->prompt_index += n; - c->prompt_buffer[c->prompt_index].size = 0; - } else { - memmove(c->prompt_buffer + c->prompt_index + n, - c->prompt_buffer + c->prompt_index, - (size + 1 - c->prompt_index) * sizeof *c->prompt_buffer); - memcpy(c->prompt_buffer + c->prompt_index, ud, - n * sizeof *c->prompt_buffer); - c->prompt_index += n; + if (n != 0) { + c->prompt_buffer = xreallocarray(c->prompt_buffer, size + n + 1, + sizeof *c->prompt_buffer); + if (c->prompt_index == size) { + memcpy(c->prompt_buffer + c->prompt_index, ud, + n * sizeof *c->prompt_buffer); + c->prompt_index += n; + c->prompt_buffer[c->prompt_index].size = 0; + } else { + memmove(c->prompt_buffer + c->prompt_index + n, + c->prompt_buffer + c->prompt_index, + (size + 1 - c->prompt_index) * + sizeof *c->prompt_buffer); + memcpy(c->prompt_buffer + c->prompt_index, ud, + n * sizeof *c->prompt_buffer); + c->prompt_index += n; + } } - if (ud != c->prompt_saved) free(ud); return (1); @@ -1839,6 +1837,7 @@ status_prompt_complete_window_menu(struct client *c, struct session *s, } if (size == 0) { menu_free(menu); + free(spm); return (NULL); } if (size == 1) { @@ -1849,6 +1848,7 @@ status_prompt_complete_window_menu(struct client *c, struct session *s, } else tmp = list[0]; free(list); + free(spm); return (tmp); } if (height > size) |