diff --git a/.tmux.metadata b/.tmux.metadata new file mode 100644 index 0000000..f839344 --- /dev/null +++ b/.tmux.metadata @@ -0,0 +1 @@ +519c08880307ef13c799cb6988b4fd11ec5c2b77 tmux-3.2a.tar.gz diff --git a/0001-Fix-memory-leaks.patch b/0001-Fix-memory-leaks.patch new file mode 100644 index 0000000..7225d73 --- /dev/null +++ b/0001-Fix-memory-leaks.patch @@ -0,0 +1,122 @@ +From 369627faddc1bba283c6afc4d473d7a495edb9a7 Mon Sep 17 00:00:00 2001 +From: Josh Boyer +Date: Fri, 7 Apr 2023 07:38:21 -0400 +Subject: [PATCH 01/12] Fix memory leaks Backport of upstream commits: + 4a753dbefc2e67c218cf41141eaa6afab00f774a + 3c65475561b25073c3b7dcbb0b6498a0535ecd59 + a9ac61469175e45c8ba58ae0360306aa06c0cd59 + 72d905f32c53ea1304b4b3206383502a23cfc0fd + +--- + cmd-display-menu.c | 6 +++++- + cmd-source-file.c | 4 +++- + format.c | 4 ++-- + key-bindings.c | 5 ++++- + popup.c | 1 + + 5 files changed, 15 insertions(+), 5 deletions(-) + +diff --git a/cmd-display-menu.c b/cmd-display-menu.c +index de423e68..d61fedbb 100644 +--- a/cmd-display-menu.c ++++ b/cmd-display-menu.c +@@ -248,6 +248,7 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item, + log_debug("%s: -y: %s = %s = %u", __func__, yp, p, *py); + free(p); + ++ format_free(ft); + return (1); + } + +@@ -391,7 +392,10 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) + else if (args_has(args, 'E')) + flags |= POPUP_CLOSEEXIT; + if (popup_display(flags, item, px, py, w, h, shellcmd, argc, argv, cwd, +- tc, s, NULL, NULL) != 0) ++ tc, s, NULL, NULL) != 0) { ++ free(cwd); + return (CMD_RETURN_NORMAL); ++ } ++ free(cwd); + return (CMD_RETURN_WAIT); + } +diff --git a/cmd-source-file.c b/cmd-source-file.c +index c1eeba58..296c31f9 100644 +--- a/cmd-source-file.c ++++ b/cmd-source-file.c +@@ -176,15 +176,17 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item) + cmdq_error(item, "%s: %s", path, error); + retval = CMD_RETURN_ERROR; + } ++ globfree(&g); + free(pattern); + continue; + } +- free(expand); + free(pattern); + + for (j = 0; j < g.gl_pathc; j++) + cmd_source_file_add(cdata, g.gl_pathv[j]); ++ globfree(&g); + } ++ free(expand); + + cdata->after = item; + cdata->retval = retval; +diff --git a/format.c b/format.c +index 512df009..673a6085 100644 +--- a/format.c ++++ b/format.c +@@ -3382,12 +3382,12 @@ found: + } + if (modifiers & FORMAT_QUOTE_SHELL) { + saved = found; +- found = xstrdup(format_quote_shell(saved)); ++ found = format_quote_shell(saved); + free(saved); + } + if (modifiers & FORMAT_QUOTE_STYLE) { + saved = found; +- found = xstrdup(format_quote_style(saved)); ++ found = format_quote_style(saved); + free(saved); + } + return (found); +diff --git a/key-bindings.c b/key-bindings.c +index 467c7f93..4df0cddc 100644 +--- a/key-bindings.c ++++ b/key-bindings.c +@@ -187,6 +187,7 @@ key_bindings_add(const char *name, key_code key, const char *note, int repeat, + { + struct key_table *table; + struct key_binding *bd; ++ char *s; + + table = key_bindings_get_table(name, 1); + +@@ -216,8 +217,10 @@ key_bindings_add(const char *name, key_code key, const char *note, int repeat, + bd->flags |= KEY_BINDING_REPEAT; + bd->cmdlist = cmdlist; + ++ s = cmd_list_print(bd->cmdlist, 0); + log_debug("%s: %#llx %s = %s", __func__, bd->key, +- key_string_lookup_key(bd->key, 1), cmd_list_print(bd->cmdlist, 0)); ++ key_string_lookup_key(bd->key, 1), s); ++ free(s); + } + + void +diff --git a/popup.c b/popup.c +index 509d182d..a98cc42a 100644 +--- a/popup.c ++++ b/popup.c +@@ -142,6 +142,7 @@ popup_draw_cb(struct client *c, __unused struct screen_redraw_ctx *ctx0) + tty_draw_line(tty, &s, 0, i, pd->sx, px, py + i, + &grid_default_cell, NULL); + } ++ screen_free(&s); + c->overlay_check = popup_check_cb; + } + +-- +2.31.1 + diff --git a/0002-Close-file-stream-on-error.patch b/0002-Close-file-stream-on-error.patch new file mode 100644 index 0000000..c416b82 --- /dev/null +++ b/0002-Close-file-stream-on-error.patch @@ -0,0 +1,32 @@ +From b4ae1931b2170d783f9a946e6f1983e3d0976107 Mon Sep 17 00:00:00 2001 +From: Josh Boyer +Date: Fri, 7 Apr 2023 11:33:56 -0400 +Subject: [PATCH 02/12] Close file stream on error + +--- + file.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/file.c b/file.c +index 974c8a37..9368b4f4 100644 +--- a/file.c ++++ b/file.c +@@ -391,6 +391,7 @@ file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata) + size = fread(buffer, 1, sizeof buffer, f); + if (evbuffer_add(cf->buffer, buffer, size) != 0) { + cf->error = ENOMEM; ++ fclose(f); + goto done; + } + if (size != sizeof buffer) +@@ -398,6 +399,7 @@ file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata) + } + if (ferror(f)) { + cf->error = EIO; ++ fclose(f); + goto done; + } + fclose(f); +-- +2.31.1 + diff --git a/0003-Fix-memory-leak-with-time_format.patch b/0003-Fix-memory-leak-with-time_format.patch new file mode 100644 index 0000000..f9c68ee --- /dev/null +++ b/0003-Fix-memory-leak-with-time_format.patch @@ -0,0 +1,32 @@ +From 5e83beff72bed8f8e96fbfe63b7a814d34205354 Mon Sep 17 00:00:00 2001 +From: Josh Boyer +Date: Fri, 7 Apr 2023 11:54:51 -0400 +Subject: [PATCH 03/12] Fix memory leak with time_format + +--- + format.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/format.c b/format.c +index 673a6085..01204b8a 100644 +--- a/format.c ++++ b/format.c +@@ -4416,6 +4416,7 @@ done: + free(sub); + format_free_modifiers(list, count); + free(copy0); ++ free(time_format); + return (0); + + fail: +@@ -4424,6 +4425,7 @@ fail: + free(sub); + format_free_modifiers(list, count); + free(copy0); ++ free(time_format); + return (-1); + } + +-- +2.31.1 + diff --git a/0004-Fix-memory-leak-with-condition-on-error-path.patch b/0004-Fix-memory-leak-with-condition-on-error-path.patch new file mode 100644 index 0000000..5ad1a00 --- /dev/null +++ b/0004-Fix-memory-leak-with-condition-on-error-path.patch @@ -0,0 +1,33 @@ +From 777edc3d865ac52837072da904748a6f70d36b8b Mon Sep 17 00:00:00 2001 +From: Josh Boyer +Date: Fri, 7 Apr 2023 12:22:06 -0400 +Subject: [PATCH 04/12] Fix memory leak with condition on error path + +--- + format.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/format.c b/format.c +index 01204b8a..6f057b5e 100644 +--- a/format.c ++++ b/format.c +@@ -4019,7 +4019,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen, + struct window_pane *wp = ft->wp; + const char *errstr, *copy, *cp, *marker = NULL; + const char *time_format = NULL; +- char *copy0, *condition, *found, *new; ++ char *copy0, *condition = NULL, *found, *new; + char *value, *left, *right, c; + size_t valuelen; + int modifiers = 0, limit = 0, width = 0; +@@ -4425,6 +4425,7 @@ fail: + free(sub); + format_free_modifiers(list, count); + free(copy0); ++ free(condition); + free(time_format); + return (-1); + } +-- +2.31.1 + diff --git a/0005-Free-s-even-if-there-is-no-expanded-format.patch b/0005-Free-s-even-if-there-is-no-expanded-format.patch new file mode 100644 index 0000000..d5e55bd --- /dev/null +++ b/0005-Free-s-even-if-there-is-no-expanded-format.patch @@ -0,0 +1,24 @@ +From 47d2223dd090b365246709f9c20ce8684259590e Mon Sep 17 00:00:00 2001 +From: Josh Boyer +Date: Fri, 7 Apr 2023 12:36:06 -0400 +Subject: [PATCH 05/12] Free s even if there is no expanded format + +--- + menu.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/menu.c b/menu.c +index 48c9ed2f..137c8c8d 100644 +--- a/menu.c ++++ b/menu.c +@@ -78,6 +78,7 @@ menu_add_item(struct menu *menu, const struct menu_item *item, + s = format_single(qitem, item->name, c, NULL, NULL, NULL); + if (*s == '\0') { /* no item if empty after format expanded */ + menu->count--; ++ free(s); + return; + } + if (*s != '-' && item->key != KEYC_UNKNOWN && item->key != KEYC_NONE) { +-- +2.31.1 + diff --git a/0006-Fix-spm-memory-leak.patch b/0006-Fix-spm-memory-leak.patch new file mode 100644 index 0000000..2912ef8 --- /dev/null +++ b/0006-Fix-spm-memory-leak.patch @@ -0,0 +1,32 @@ +From 8a6f2d39bf883a05145651e04ae1bdb2fbba8c34 Mon Sep 17 00:00:00 2001 +From: Josh Boyer +Date: Fri, 7 Apr 2023 12:50:51 -0400 +Subject: [PATCH 06/12] Fix spm memory leak + +--- + status.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/status.c b/status.c +index f4418500..116b28c0 100644 +--- a/status.c ++++ b/status.c +@@ -1628,6 +1628,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) { +@@ -1638,6 +1639,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) +-- +2.31.1 + diff --git a/0007-Don-t-leak-the-original-value-memory.patch b/0007-Don-t-leak-the-original-value-memory.patch new file mode 100644 index 0000000..8ead62f --- /dev/null +++ b/0007-Don-t-leak-the-original-value-memory.patch @@ -0,0 +1,27 @@ +From 43f00a273beaf63778cb34c925489f0f003ebef7 Mon Sep 17 00:00:00 2001 +From: Josh Boyer +Date: Fri, 7 Apr 2023 13:02:37 -0400 +Subject: [PATCH 07/12] Don't leak the original value memory + +--- + window-customize.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/window-customize.c b/window-customize.c +index 34a13f73..50cfbdf7 100644 +--- a/window-customize.c ++++ b/window-customize.c +@@ -806,6 +806,10 @@ window_customize_draw_option(struct window_customize_modedata *data, + break; + } + } ++ ++ free(value); ++ value = NULL; ++ + if (wo != NULL && options_owner(o) != wo) { + parent = options_get_only(wo, name); + if (parent != NULL) { +-- +2.31.1 + diff --git a/0008-Don-t-leak-expanded.patch b/0008-Don-t-leak-expanded.patch new file mode 100644 index 0000000..44589aa --- /dev/null +++ b/0008-Don-t-leak-expanded.patch @@ -0,0 +1,41 @@ +From c4860205ea28136a75bfbfb5f70a793770c73c82 Mon Sep 17 00:00:00 2001 +From: Josh Boyer +Date: Fri, 7 Apr 2023 13:05:09 -0400 +Subject: [PATCH 08/12] Don't leak expanded + +--- + window-customize.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/window-customize.c b/window-customize.c +index 50cfbdf7..7d3cbb18 100644 +--- a/window-customize.c ++++ b/window-customize.c +@@ -658,7 +658,7 @@ window_customize_draw_option(struct window_customize_modedata *data, + struct grid_cell gc; + const char **choice, *text, *name; + const char *space = "", *unit = ""; +- char *value = NULL, *expanded; ++ char *value = NULL, *expanded = NULL; + char *default_value = NULL; + char choices[256] = ""; + struct cmd_find_state fs; +@@ -745,6 +745,7 @@ window_customize_draw_option(struct window_customize_modedata *data, + goto out; + } + free(expanded); ++ expanded = NULL; + } + if (oe != NULL && oe->type == OPTIONS_TABLE_CHOICE) { + for (choice = oe->choices; *choice != NULL; choice++) { +@@ -835,6 +836,7 @@ window_customize_draw_option(struct window_customize_modedata *data, + out: + free(value); + free(default_value); ++ free(expanded); + format_free(ft); + } + +-- +2.31.1 + diff --git a/0009-Fix-buf-memory-leak.patch b/0009-Fix-buf-memory-leak.patch new file mode 100644 index 0000000..8a72cc2 --- /dev/null +++ b/0009-Fix-buf-memory-leak.patch @@ -0,0 +1,26 @@ +From aea74c289c6000b86964ad0bb9ac1a05bba2456a Mon Sep 17 00:00:00 2001 +From: Josh Boyer +Date: Fri, 7 Apr 2023 16:29:55 -0400 +Subject: [PATCH 09/12] Fix buf memory leak + +--- + cmd-capture-pane.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c +index 6f37bc8f..341d1048 100644 +--- a/cmd-capture-pane.c ++++ b/cmd-capture-pane.c +@@ -226,8 +226,8 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item) + } + file_print_buffer(c, buf, len); + file_print(c, "\n"); +- free(buf); + } ++ free(buf); + } else { + bufname = NULL; + if (args_has(args, 'b')) +-- +2.31.1 + diff --git a/tmux.spec b/tmux.spec index 1da5779..7feded6 100644 --- a/tmux.spec +++ b/tmux.spec @@ -2,7 +2,7 @@ Name: tmux Version: 3.2a -Release: 4%{?dist} +Release: 5%{?dist} Summary: A terminal multiplexer # Most of the source is ISC licensed; some of the files in compat/ are 2 and @@ -12,6 +12,15 @@ URL: https://tmux.github.io/ Source0: https://github.com/tmux/%{name}/releases/download/%{version}/%{name}-%{version}.tar.gz # Examples has been removed - so include the bash_completion here Source1: bash_completion_tmux.sh +Patch1: 0001-Fix-memory-leaks.patch +Patch2: 0002-Close-file-stream-on-error.patch +Patch3: 0003-Fix-memory-leak-with-time_format.patch +Patch4: 0004-Fix-memory-leak-with-condition-on-error-path.patch +Patch5: 0005-Free-s-even-if-there-is-no-expanded-format.patch +Patch6: 0006-Fix-spm-memory-leak.patch +Patch7: 0007-Don-t-leak-the-original-value-memory.patch +Patch8: 0008-Don-t-leak-expanded.patch +Patch9: 0009-Fix-buf-memory-leak.patch BuildRequires: make BuildRequires: gcc @@ -32,6 +41,7 @@ as GNU Screen. %prep %setup +%autopatch %build @@ -72,6 +82,10 @@ fi %{_datadir}/bash-completion/completions/tmux %changelog +* Mon Apr 10 2023 Josh Boyer - 3.2a-5 +- Backport a number of memory leak fixes + Resolves: rhbz#1938885 + * Fri Dec 03 2021 David Cantrell - 3.2a-4 - Rebuild Resolves: rhbz#2003007