From c27fdae01c0e91f576e80f3098a5c4345ad58c5c Mon Sep 17 00:00:00 2001 From: Lv Ying Date: Sat, 31 Jul 2021 14:47:05 +0800 Subject: [PATCH] [Backport]ldconfig: Fix memory leaks Signed-off-by: Lv Ying (cherry picked from commit 60e54e1200aebdd16099fcc64deb61c24f8504f7) --- backport-ldconfig-Fix-memory-leaks.patch | 75 ++++++++++++++++++++++++ glibc.spec | 7 ++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 backport-ldconfig-Fix-memory-leaks.patch diff --git a/backport-ldconfig-Fix-memory-leaks.patch b/backport-ldconfig-Fix-memory-leaks.patch new file mode 100644 index 0000000..1fb4f7a --- /dev/null +++ b/backport-ldconfig-Fix-memory-leaks.patch @@ -0,0 +1,75 @@ +From f97b794d7aab9504894b1991f2264dd6914bc24b Mon Sep 17 00:00:00 2001 +From: Siddhesh Poyarekar +Date: Tue, 18 May 2021 09:29:02 +0530 +Subject: [PATCH] ldconfig: Fix memory leaks + +Coverity discovered that paths allocated by chroot_canon are not freed +in a couple of routines in ldconfig. + +Reviewed-by: Adhemerval Zanella +--- + elf/ldconfig.c | 20 ++++++++++++++------ + 1 file changed, 14 insertions(+), 6 deletions(-) + +diff --git a/elf/ldconfig.c b/elf/ldconfig.c +index fbdd814edf59..be87bb383dac 100644 +--- a/elf/ldconfig.c ++++ b/elf/ldconfig.c +@@ -601,16 +601,14 @@ manual_link (char *library) + if (lstat64 (real_library, &stat_buf)) + { + error (0, errno, _("Cannot lstat %s"), library); +- free (path); +- return; ++ goto out; + } + /* We don't want links here! */ + else if (!S_ISREG (stat_buf.st_mode)) + { + error (0, 0, _("Ignored file %s since it is not a regular file."), + library); +- free (path); +- return; ++ goto out; + } + + if (process_file (real_library, library, libname, &flag, &osversion, +@@ -618,14 +616,16 @@ manual_link (char *library) + { + error (0, 0, _("No link created since soname could not be found for %s"), + library); +- free (path); +- return; ++ goto out; + } + if (soname == NULL) + soname = implicit_soname (libname, flag); + create_links (real_path, path, libname, soname); + free (soname); ++out: + free (path); ++ if (path != real_path) ++ free (real_path); + } + + +@@ -796,8 +796,16 @@ search_dir (const struct dir_entry *entry) + /* Remove stale symlinks. */ + if (opt_link && strstr (direntry->d_name, ".so.")) + unlink (real_file_name); ++ ++ if (opt_chroot != NULL) ++ free (target_name); ++ + continue; + } ++ ++ if (opt_chroot != NULL) ++ free (target_name); ++ + is_dir = S_ISDIR (stat_buf.st_mode); + + /* lstat_buf is later stored, update contents. */ +-- +2.18.4 + diff --git a/glibc.spec b/glibc.spec index 116765c..e5167a3 100644 --- a/glibc.spec +++ b/glibc.spec @@ -59,7 +59,7 @@ ############################################################################## Name: glibc Version: 2.28 -Release: 73 +Release: 74 Summary: The GNU libc libraries License: %{all_license} URL: http://www.gnu.org/software/glibc/ @@ -131,6 +131,7 @@ Patch47: backport-x86-64-Align-child-stack-to-16-bytes-BZ-27902.patch Patch48: backport-ldconfig-handle-.dynstr-located-in-separate-segment-.patch Patch49: backport-CVE-2021-35942-wordexp-handle-overflow-in-positional-parameter-numb.patch Patch50: backport-malloc-Initiate-tcache-shutdown-even-without-allocat.patch +Patch51: backport-ldconfig-Fix-memory-leaks.patch Provides: ldconfig rtld(GNU_HASH) bundled(gnulib) @@ -1155,6 +1156,10 @@ fi %doc hesiod/README.hesiod %changelog +* Sat Jul 31 2021 Lv Ying - 2.28-74 +- ldconfig: Fix memory leaks + https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=468d772e81e9842f4f73431c164b4a12f13d8658 + * Sat Jul 3 2021 Qingqing Li - 2.28-73 - malloc: tcache shutdown sequence does not work if the thread never allocated anything. (bug 28028) https://sourceware.org/bugzilla/show_bug.cgi?id=28028 -- Gitee