62e5e2
From 8ff11a8eccc41914478e92231500fc47fefa6779 Mon Sep 17 00:00:00 2001
62e5e2
From: Jonathan Wakely <boost@kayari.org>
62e5e2
Date: Wed, 10 Oct 2018 17:17:10 +0100
62e5e2
Subject: [PATCH] Fix memory leak
62e5e2
62e5e2
If vsnprintf returns -1 then the buffer should be freed before returning.
62e5e2
---
62e5e2
 src/engine/debugger.c | 5 +++--
62e5e2
 1 file changed, 3 insertions(+), 2 deletions(-)
62e5e2
62e5e2
diff --git a/src/engine/debugger.c b/src/engine/debugger.c
62e5e2
index 3c811b4557..d849d064a9 100644
62e5e2
--- a/tools/build/src/engine/debugger.c
62e5e2
+++ b/tools/build/src/engine/debugger.c
62e5e2
@@ -860,10 +860,11 @@ static const char * debug_format_message( const char * format, va_list vargs )
62e5e2
         result = vsnprintf( buf, sz, format, args );
62e5e2
         #endif
62e5e2
         va_end( args );
62e5e2
+        if ( 0 <= result && result < sz )
62e5e2
+	    return buf;
62e5e2
+        free( buf );
62e5e2
         if ( result < 0 )
62e5e2
             return 0;
62e5e2
-        if ( result < sz ) return buf;
62e5e2
-        free( buf );
62e5e2
         sz = result + 1;
62e5e2
     }
62e5e2
 }