[PATCH 2/2] _scanf.c: fix a potential memory leak (in case of "m" modifier)

Pirmin Walthert infos at nappsoft.com
Thu Apr 4 21:34:27 UTC 2013


From: root <root at yarc.(none)>

This fixes a potential memory leak in case of "m" modifier set
and (sc.width > 0).

Signed-off-by: Pirmin Walthert <infos at nappsoft.com>
---
 libc/stdio/_scanf.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/stdio/_scanf.c b/libc/stdio/_scanf.c
index fe33386..a7592b6 100644
--- a/libc/stdio/_scanf.c
+++ b/libc/stdio/_scanf.c
@@ -1383,11 +1383,11 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
 						i += psfs.store;
 					}
 					__scan_ungetc(&sc);
+					if (psfs.flags & FLAG_MALLOC)
+						*ptr = b;
 					if (sc.width > 0) {	/* Failed to read all required. */
 						goto DONE;
 					}
-					if (psfs.flags & FLAG_MALLOC)
-						*ptr = b;
 					psfs.cnt += psfs.store;
 					goto NEXT_FMT;
 				}
-- 
1.7.10.4



More information about the uClibc mailing list