winpr/utils/wlog: Fix leak found by covscan
authorOndrej Holy <oholy@redhat.com>
Tue, 21 Aug 2018 08:27:56 +0000 (10:27 +0200)
committerOndrej Holy <oholy@redhat.com>
Thu, 23 Aug 2018 07:11:24 +0000 (09:11 +0200)
leaked_storage: Variable "result" going out of scope leaks the storage it points to.
leaked_storage: Variable "bt" going out of scope leaks the storage it points to.

winpr/libwinpr/utils/wlog/UdpAppender.c
winpr/libwinpr/utils/wlog/wlog.c

index 392c8e6..0bfd74a 100644 (file)
@@ -81,6 +81,7 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender)
 
        memcpy(&udpAppender->targetAddr, result->ai_addr, result->ai_addrlen);
        udpAppender->targetAddrLen = (int) result->ai_addrlen;
+       freeaddrinfo(result);
        return TRUE;
 }
 
index 285df1c..32cb0de 100644 (file)
@@ -168,7 +168,8 @@ fail:
 
 static BOOL log_recursion(LPCSTR file, LPCSTR fkt, int line)
 {
-       char** msg;
+       BOOL status = FALSE;
+       char** msg = NULL;
        size_t used, i;
        void* bt = winpr_backtrace(20);
 #if defined(ANDROID)
@@ -181,37 +182,39 @@ static BOOL log_recursion(LPCSTR file, LPCSTR fkt, int line)
        msg = winpr_backtrace_symbols(bt, &used);
 
        if (!msg)
-               return FALSE;
+               goto out;
 
 #if defined(ANDROID)
 
        if (__android_log_print(ANDROID_LOG_FATAL, tag, "Recursion detected!!!") < 0)
-               return FALSE;
+               goto out;
 
        if (__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file,
                                line) < 0)
-               return FALSE;
+               goto out;
 
        for (i = 0; i < used; i++)
                if (__android_log_print(ANDROID_LOG_FATAL, tag, "%zd: %s", i, msg[i]) < 0)
-                       return FALSE;
+                       goto out;
 
 #else
 
        if (fprintf(stderr, "[%s]: Recursion detected!\n", fkt) < 0)
-               return FALSE;
+               goto out;
 
        if (fprintf(stderr, "[%s]: Check %s:%d\n", fkt, file, line) < 0)
-               return FALSE;
+               goto out;
 
        for (i = 0; i < used; i++)
                if (fprintf(stderr, "%s: %"PRIuz": %s\n", fkt, i, msg[i]) < 0)
-                       return FALSE;
+                       goto out;
 
 #endif
+       status = TRUE;
+out:
        free(msg);
        winpr_backtrace_free(bt);
-       return TRUE;
+       return status;
 }
 
 static BOOL WLog_Write(wLog* log, wLogMessage* message)