From 90663e9c814a919fa1fb41a878c06ef2fae58ed2 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 9 Jul 2020 21:52:24 +0000 Subject: Fix memory leak in __printf_fp_l (bug 26215). __printf_fp_l has a memory leak in the case of some I/O errors, where both buffer and wbuffer have been malloced but the handling of I/O errors only frees wbuffer. This patch fixes this by moving the declaration of buffer to an outer scope and ensuring that it is freed when wbuffer is freed. Tested for x86_64 and x86. --- stdio-common/Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'stdio-common/Makefile') diff --git a/stdio-common/Makefile b/stdio-common/Makefile index dc3fd38a19..8475fd1f09 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -68,7 +68,8 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \ scanf14a scanf16a \ tst-printf-bz25691 \ tst-vfprintf-width-prec-alloc \ - tst-printf-fp-free + tst-printf-fp-free \ + tst-printf-fp-leak test-srcs = tst-unbputc tst-printf tst-printfsz-islongdouble @@ -80,12 +81,14 @@ tests-special += $(objpfx)tst-unbputc.out $(objpfx)tst-printf.out \ $(objpfx)tst-vfprintf-width-prec-mem.out \ $(objpfx)tst-printfsz-islongdouble.out \ $(objpfx)tst-printf-bz25691-mem.out \ - $(objpfx)tst-printf-fp-free-mem.out + $(objpfx)tst-printf-fp-free-mem.out \ + $(objpfx)tst-printf-fp-leak-mem.out generated += tst-printf-bz18872.c tst-printf-bz18872.mtrace \ tst-printf-bz18872-mem.out \ tst-vfprintf-width-prec.mtrace tst-vfprintf-width-prec-mem.out \ tst-printf-bz25691.mtrace tst-printf-bz25691-mem.out \ - tst-printf-fp-free.mtrace tst-printf-fp-free-mem.out + tst-printf-fp-free.mtrace tst-printf-fp-free-mem.out \ + tst-printf-fp-leak.mtrace tst-printf-fp-leak-mem.out endif tests-special += $(objpfx)tst-errno-manual.out @@ -113,6 +116,8 @@ tst-printf-bz25691-ENV = \ MALLOC_TRACE=$(objpfx)tst-printf-bz25691.mtrace tst-printf-fp-free-ENV = \ MALLOC_TRACE=$(objpfx)tst-printf-fp-free.mtrace +tst-printf-fp-leak-ENV = \ + MALLOC_TRACE=$(objpfx)tst-printf-fp-leak.mtrace $(objpfx)tst-unbputc.out: tst-unbputc.sh $(objpfx)tst-unbputc $(SHELL) $< $(common-objpfx) '$(test-program-prefix)' > $@; \ -- cgit 1.4.1