From d8794ca0ac1769c25204b78dd5ff1b2052d84d79 Mon Sep 17 00:00:00 2001 From: wangjun Date: Tue, 29 Nov 2022 20:29:52 +0800 Subject: [PATCH] Intergrate the memory leakage patch from the upstream community. --- ncurses-memoryleak.patch | 101 +++++++++++++++++++++++++++++++++++++++ ncurses.spec | 9 +++- 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 ncurses-memoryleak.patch diff --git a/ncurses-memoryleak.patch b/ncurses-memoryleak.patch new file mode 100644 index 0000000..5eabbb3 --- /dev/null +++ b/ncurses-memoryleak.patch @@ -0,0 +1,101 @@ +diff --git a/ncurses/tinfo/db_iterator.c b/ncurses/tinfo/db_iterator.c +index f072668..11a807a 100644 +--- a/ncurses/tinfo/db_iterator.c ++++ b/ncurses/tinfo/db_iterator.c +@@ -202,6 +202,13 @@ free_cache(void) + FreeAndNull(my_list); + } + ++static void ++update_tic_dir(const char *update) ++{ ++ free((char *) TicDirectory); ++ TicDirectory = update; ++} ++ + /* + * Record the "official" location of the terminfo directory, according to + * the place where we're writing to, or the normal default, if not. +@@ -211,8 +218,9 @@ _nc_tic_dir(const char *path) + { + T(("_nc_tic_dir %s", NonNull(path))); + if (!KeepTicDirectory) { +- if (path != 0) { +- TicDirectory = path; ++ if (path != NULL) { ++ if (path != TicDirectory) ++ update_tic_dir(strdup(path)); + HaveTicDirectory = TRUE; + } else if (HaveTicDirectory == 0) { + if (use_terminfo_vars()) { +@@ -444,5 +452,6 @@ _nc_db_iterator_leaks(void) + FreeIfNeeded(my_vars[which].value); + my_vars[which].value = 0; + } ++ update_tic_dir(NULL); + } + #endif +diff --git a/ncurses/tinfo/free_ttype.c b/ncurses/tinfo/free_ttype.c +index 7f0fbcc..74a8968 100644 +--- a/ncurses/tinfo/free_ttype.c ++++ b/ncurses/tinfo/free_ttype.c +@@ -48,7 +48,7 @@ MODULE_ID("$Id: free_ttype.c,v 1.19 2020/02/02 23:34:34 tom Exp $") + static void + really_free_termtype(TERMTYPE2 *ptr, bool freeStrings) + { +- T(("_nc_free_termtype(%s)", ptr->term_names)); ++ T(("really_free_termtype(%s) %d", ptr->term_names, freeStrings)); + + if (freeStrings) { + FreeIfNeeded(ptr->str_table); +diff --git a/ncurses/tinfo/lib_cur_term.c b/ncurses/tinfo/lib_cur_term.c +index 0373aeb..22f37dc 100644 +--- a/ncurses/tinfo/lib_cur_term.c ++++ b/ncurses/tinfo/lib_cur_term.c +@@ -147,7 +147,11 @@ NCURSES_SP_NAME(del_curterm) (NCURSES_SP_DCLx TERMINAL *termp) + ); + + #if NCURSES_EXT_NUMBERS ++#if NCURSES_EXT_COLORS + _nc_free_termtype(&termp->type); ++#else ++ _nc_free_termtype2(&termp->type); ++#endif + #endif + _nc_free_termtype2(&TerminalType(termp)); + if (termp == cur) +diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c +index cab4757..a1df57e 100644 +--- a/ncurses/tinfo/write_entry.c ++++ b/ncurses/tinfo/write_entry.c +@@ -248,7 +248,7 @@ _nc_set_writedir(const char *dir) + || getcwd(actual, sizeof(actual)) == 0) + _nc_err_abort("%s: not a directory", destination); + #endif +- _nc_keep_tic_dir(strdup(actual)); ++ _nc_keep_tic_dir(actual); + } + + /* +diff --git a/progs/tic.c b/progs/tic.c +index dba2890..23a21f2 100644 +--- a/progs/tic.c ++++ b/progs/tic.c +@@ -644,7 +644,7 @@ show_databases(const char *outdir) + const char *tried = 0; + + if (outdir == NULL) { +- outdir = _nc_tic_dir(0); ++ outdir = _nc_tic_dir(NULL); + } + if ((result = valid_db_path(outdir)) != 0) { + printf("%s\n", result); +@@ -1081,7 +1081,7 @@ main(int argc, char *argv[]) + if (total != 0) + fprintf(log_fp, "%d entries written to %s\n", + total, +- _nc_tic_dir((char *) 0)); ++ _nc_tic_dir(NULL)); + else + fprintf(log_fp, "No entries written\n"); + } diff --git a/ncurses.spec b/ncurses.spec index 46f662c..d63855c 100644 --- a/ncurses.spec +++ b/ncurses.spec @@ -1,6 +1,6 @@ Name: ncurses Version: 6.3 -Release: 5 +Release: 6 Summary: Terminal control library License: MIT URL: https://invisible-island.net/ncurses/ncurses.html @@ -11,6 +11,7 @@ Patch9: ncurses-libs.patch Patch11: ncurses-urxvt.patch Patch12: ncurses-kbs.patch Patch13: backport-CVE-2022-29458.patch +Patch14: ncurses-memoryleak.patch BuildRequires: gcc gcc-c++ gpm-devel pkgconfig @@ -242,6 +243,12 @@ xz NEWS %{_mandir}/man7/* %changelog +* Tue Nov 29 2022 wangjun - 6.3-6 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:intergrate the memory leakage patch from the upstream community + * Thu Nov 10 2022 yanglu - 6.3-5 - Type:bugfix - CVE:NA -- Gitee