!199 mtrace: use a static buffer for printing, fix upstream bug BZ #25947

From: @liqingqing_1229
Reviewed-by: @wangbin224
Signed-off-by: @wangbin224
This commit is contained in:
openeuler-ci-bot 2021-09-27 11:42:26 +00:00 committed by Gitee
commit d56bab677b
2 changed files with 67 additions and 1 deletions

View File

@ -63,7 +63,7 @@
############################################################################## ##############################################################################
Name: glibc Name: glibc
Version: 2.34 Version: 2.34
Release: 6 Release: 7
Summary: The GNU libc libraries Summary: The GNU libc libraries
License: %{all_license} License: %{all_license}
URL: http://www.gnu.org/software/glibc/ 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 Patch17: 5-5-AArch64-Improve-A64FX-memset-medium-loops.patch
Patch18: elf-Unconditionally-use-__ehdr_start.patch Patch18: elf-Unconditionally-use-__ehdr_start.patch
Patch19: aarch64-Make-elf_machine_-load_address-dynamic-robus.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 #Patch9000: turn-REP_STOSB_THRESHOLD-from-2k-to-1M.patch
Patch9001: delete-no-hard-link-to-avoid-all_language-package-to.patch Patch9001: delete-no-hard-link-to-avoid-all_language-package-to.patch
@ -1188,6 +1189,10 @@ fi
%doc hesiod/README.hesiod %doc hesiod/README.hesiod
%changelog %changelog
* Mon Sep 27 2021 Qingqing Li<liqingqing3@huawei.com> - 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<liqingqing3@huawei.com> - 2.34-6 * Sun Sep 26 2021 Qingqing Li<liqingqing3@huawei.com> - 2.34-6
- elf: Unconditionally use __ehdr_start. - elf: Unconditionally use __ehdr_start.
- aarch64: Make elf_machine_{load_addr,dynamic} robust [BZ #28203]. - aarch64: Make elf_machine_{load_addr,dynamic} robust [BZ #28203].

View File

@ -0,0 +1,61 @@
From dc906e94f7033892dadbd91718349f19e1376391 Mon Sep 17 00:00:00 2001
From: Siddhesh Poyarekar <siddhesh@sourceware.org>
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 <dj@redhat.com>
---
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 <kernel-features.h>
-#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