From 207d92d04372e402208ee487f336ecd1cfa00cdc Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Sat, 16 Jun 2001 05:37:57 +0000 Subject: [PATCH] free memory that gets allocated by vfprintf when str == NULL PR: misc/26044 MFC after: 1 week --- lib/libc/stdio/snprintf.c | 2 ++ lib/libc/stdio/sprintf.c | 2 ++ lib/libc/stdio/vsnprintf.c | 2 ++ lib/libc/stdio/vsprintf.c | 2 ++ 4 files changed, 8 insertions(+) diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c index fe21129bc13f..3463c05f9876 100644 --- a/lib/libc/stdio/snprintf.c +++ b/lib/libc/stdio/snprintf.c @@ -87,5 +87,7 @@ snprintf(str, n, fmt, va_alist) if (on > 0) *f._p = '\0'; va_end(ap); + if (str == NULL) + free(f._bf._base); return (ret); } diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c index a8100961fa4d..04910e02e6cd 100644 --- a/lib/libc/stdio/sprintf.c +++ b/lib/libc/stdio/sprintf.c @@ -77,5 +77,7 @@ sprintf(str, fmt, va_alist) ret = __vfprintf(&f, fmt, ap); va_end(ap); *f._p = 0; + if (str == NULL) + free(f._bf._base); return (ret); } diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index b301b08f9fe5..3b762599933f 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -69,5 +69,7 @@ vsnprintf(str, n, fmt, ap) ret = __vfprintf(&f, fmt, ap); if (on > 0) *f._p = '\0'; + if (str == NULL) + free(f._bf._base); return (ret); } diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c index dbfd339e2d3e..9bcd0753e982 100644 --- a/lib/libc/stdio/vsprintf.c +++ b/lib/libc/stdio/vsprintf.c @@ -61,5 +61,7 @@ vsprintf(str, fmt, ap) f._bf._size = f._w = INT_MAX; ret = __vfprintf(&f, fmt, ap); *f._p = 0; + if (str == NULL) + free(f._bf._base); return (ret); }