From 8b0605e3bfb2c5f594f8d16b2ff802e59df24c18 Mon Sep 17 00:00:00 2001 From: liqingqing_1229 Date: Mon, 27 Sep 2021 19:17:12 +0800 Subject: [PATCH] mtrace: use a static buffer for printing, fix upstream bug BZ #25947 --- glibc.spec | 7 ++- ...-static-buffer-for-printing-BZ-25947.patch | 61 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 mtrace-Use-a-static-buffer-for-printing-BZ-25947.patch diff --git a/glibc.spec b/glibc.spec index a4c1625..b6f43de 100644 --- a/glibc.spec +++ b/glibc.spec @@ -63,7 +63,7 @@ ############################################################################## Name: glibc Version: 2.34 -Release: 6 +Release: 7 Summary: The GNU libc libraries License: %{all_license} URL: http://www.gnu.org/software/glibc/ @@ -97,6 +97,7 @@ Patch16: 4-5-AArch64-Improve-A64FX-memset-by-removing-unroll3.patch Patch17: 5-5-AArch64-Improve-A64FX-memset-medium-loops.patch Patch18: elf-Unconditionally-use-__ehdr_start.patch Patch19: aarch64-Make-elf_machine_-load_address-dynamic-robus.patch +Patch20: mtrace-Use-a-static-buffer-for-printing-BZ-25947.patch #Patch9000: turn-REP_STOSB_THRESHOLD-from-2k-to-1M.patch Patch9001: delete-no-hard-link-to-avoid-all_language-package-to.patch @@ -1188,6 +1189,10 @@ fi %doc hesiod/README.hesiod %changelog +* Mon Sep 27 2021 Qingqing Li - 2.34-7 +- mtrace: use a static buffer for printing, fix memory leak. + upstream link: https://sourceware.org/bugzilla/show_bug.cgi?id=25947 + * Sun Sep 26 2021 Qingqing Li - 2.34-6 - elf: Unconditionally use __ehdr_start. - aarch64: Make elf_machine_{load_addr,dynamic} robust [BZ #28203]. diff --git a/mtrace-Use-a-static-buffer-for-printing-BZ-25947.patch b/mtrace-Use-a-static-buffer-for-printing-BZ-25947.patch new file mode 100644 index 0000000..9c25d43 --- /dev/null +++ b/mtrace-Use-a-static-buffer-for-printing-BZ-25947.patch @@ -0,0 +1,61 @@ +From dc906e94f7033892dadbd91718349f19e1376391 Mon Sep 17 00:00:00 2001 +From: Siddhesh Poyarekar +Date: Thu, 12 Aug 2021 06:38:15 +0530 +Subject: [PATCH] mtrace: Use a static buffer for printing [BZ #25947] + +Use a static buffer for mtrace printing now that it no longer adds to +default libc footprint. + +Reviewed-by: DJ Delorie +--- + malloc/mtrace-impl.c | 14 +++----------- + 1 file changed, 3 insertions(+), 11 deletions(-) + +diff --git a/malloc/mtrace-impl.c b/malloc/mtrace-impl.c +index 0e10ab7..83008ca 100644 +--- a/malloc/mtrace-impl.c ++++ b/malloc/mtrace-impl.c +@@ -34,11 +34,8 @@ + + #include + +-#define TRACE_BUFFER_SIZE 512 +- + static FILE *mallstream; + static const char mallenv[] = "MALLOC_TRACE"; +-static char *malloc_trace_buffer; + + static void + tr_where (const void *caller, Dl_info *info) +@@ -184,16 +181,13 @@ do_mtrace (void) + mallfile = secure_getenv (mallenv); + if (mallfile != NULL) + { +- char *mtb = malloc (TRACE_BUFFER_SIZE); +- if (mtb == NULL) +- return; +- + mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "wce"); + if (mallstream != NULL) + { + /* Be sure it doesn't malloc its buffer! */ +- malloc_trace_buffer = mtb; +- setvbuf (mallstream, malloc_trace_buffer, _IOFBF, TRACE_BUFFER_SIZE); ++ static char tracebuf [512]; ++ ++ setvbuf (mallstream, tracebuf, _IOFBF, sizeof (tracebuf)); + fprintf (mallstream, "= Start\n"); + if (!added_atexit_handler) + { +@@ -203,8 +197,6 @@ do_mtrace (void) + } + __malloc_debug_enable (MALLOC_MTRACE_HOOK); + } +- else +- free (mtb); + } + } + +-- +1.8.3.1 + -- Gitee