[glib: 1/5] gprintf: Fix a memory leak with an invalid format in g_vasprintf()




commit 7329c6e09bf59ccae2d8d3e788ce43bb6af6c3db
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Mar 9 14:07:34 2022 +0000

    gprintf: Fix a memory leak with an invalid format in g_vasprintf()
    
    If using the fallback implementation of `g_vasprintf()`.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Coverity CID: #1474726

 glib/gprintf.c | 6 ++++++
 1 file changed, 6 insertions(+)
---
diff --git a/glib/gprintf.c b/glib/gprintf.c
index 555a630bc..0e094f00f 100644
--- a/glib/gprintf.c
+++ b/glib/gprintf.c
@@ -356,6 +356,12 @@ g_vasprintf (gchar      **string,
 
     len = _g_vsprintf (*string, format, args2);
     va_end (args2);
+
+    if (len < 0)
+      {
+        g_free (*string);
+        *string = NULL;
+      }
   }
 #endif
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]