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