Fix memory leaks reported by Lu Ming Yin.

This commit is contained in:
nicm 2024-05-15 08:39:30 +00:00
parent a18d1146aa
commit bfd65398a9
2 changed files with 23 additions and 22 deletions

View File

@ -92,6 +92,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
cdata->confirm_key = confirm_key[0]; cdata->confirm_key = confirm_key[0];
else { else {
cmdq_error(item, "invalid confirm key"); cmdq_error(item, "invalid confirm key");
free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} }
@ -102,8 +103,8 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
xasprintf(&new_prompt, "%s ", prompt); xasprintf(&new_prompt, "%s ", prompt);
else { else {
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name; cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ", xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ", cmd,
cmd, cdata->confirm_key); cdata->confirm_key);
} }
status_prompt_set(tc, target, new_prompt, NULL, status_prompt_set(tc, target, new_prompt, NULL,

View File

@ -994,8 +994,7 @@ status_prompt_paste(struct client *c)
if ((pb = paste_get_top(NULL)) == NULL) if ((pb = paste_get_top(NULL)) == NULL)
return (0); return (0);
bufdata = paste_buffer_data(pb, &bufsize); bufdata = paste_buffer_data(pb, &bufsize);
ud = xreallocarray(NULL, bufsize + 1, sizeof *ud); ud = udp = xreallocarray(NULL, bufsize + 1, sizeof *ud);
udp = ud;
for (i = 0; i != bufsize; /* nothing */) { for (i = 0; i != bufsize; /* nothing */) {
more = utf8_open(udp, bufdata[i]); more = utf8_open(udp, bufdata[i]);
if (more == UTF8_MORE) { if (more == UTF8_MORE) {
@ -1016,9 +1015,7 @@ status_prompt_paste(struct client *c)
udp->size = 0; udp->size = 0;
n = udp - ud; n = udp - ud;
} }
if (n == 0) if (n != 0) {
return (0);
c->prompt_buffer = xreallocarray(c->prompt_buffer, size + n + 1, c->prompt_buffer = xreallocarray(c->prompt_buffer, size + n + 1,
sizeof *c->prompt_buffer); sizeof *c->prompt_buffer);
if (c->prompt_index == size) { if (c->prompt_index == size) {
@ -1029,12 +1026,13 @@ status_prompt_paste(struct client *c)
} else { } else {
memmove(c->prompt_buffer + c->prompt_index + n, memmove(c->prompt_buffer + c->prompt_index + n,
c->prompt_buffer + c->prompt_index, c->prompt_buffer + c->prompt_index,
(size + 1 - c->prompt_index) * sizeof *c->prompt_buffer); (size + 1 - c->prompt_index) *
sizeof *c->prompt_buffer);
memcpy(c->prompt_buffer + c->prompt_index, ud, memcpy(c->prompt_buffer + c->prompt_index, ud,
n * sizeof *c->prompt_buffer); n * sizeof *c->prompt_buffer);
c->prompt_index += n; c->prompt_index += n;
} }
}
if (ud != c->prompt_saved) if (ud != c->prompt_saved)
free(ud); free(ud);
return (1); return (1);
@ -1839,6 +1837,7 @@ status_prompt_complete_window_menu(struct client *c, struct session *s,
} }
if (size == 0) { if (size == 0) {
menu_free(menu); menu_free(menu);
free(spm);
return (NULL); return (NULL);
} }
if (size == 1) { if (size == 1) {
@ -1849,6 +1848,7 @@ status_prompt_complete_window_menu(struct client *c, struct session *s,
} else } else
tmp = list[0]; tmp = list[0];
free(list); free(list);
free(spm);
return (tmp); return (tmp);
} }
if (height > size) if (height > size)