channels/audin: Fix leak found by covscan
authorOndrej Holy <oholy@redhat.com>
Fri, 17 Aug 2018 10:30:33 +0000 (12:30 +0200)
committerOndrej Holy <oholy@redhat.com>
Wed, 22 Aug 2018 11:35:43 +0000 (13:35 +0200)
leaked_storage: Variable out going out of scope leaks the storage it points to.

channels/audin/client/audin_main.c

index 1e3aa5a..5a854b7 100644 (file)
@@ -225,7 +225,10 @@ static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* c
                AUDIO_FORMAT format = { 0 };
 
                if (Stream_GetRemainingLength(s) < 18)
-                       return ERROR_INVALID_DATA;
+               {
+                       error = ERROR_INVALID_DATA;
+                       goto out;
+               }
 
                Stream_Read_UINT16(s, format.wFormatTag);
                Stream_Read_UINT16(s, format.nChannels);
@@ -236,14 +239,20 @@ static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* c
                Stream_Read_UINT16(s, format.cbSize);
 
                if (Stream_GetRemainingLength(s) < format.cbSize)
-                       return ERROR_INVALID_DATA;
+               {
+                       error = ERROR_INVALID_DATA;
+                       goto out;
+               }
 
                if (format.cbSize > 0)
                {
                        format.data = malloc(format.cbSize);
 
                        if (!format.data)
-                               return ERROR_OUTOFMEMORY;
+                       {
+                               error = ERROR_OUTOFMEMORY;
+                               goto out;
+                       }
 
                        memcpy(format.data, Stream_Pointer(s), format.cbSize);
                        Stream_Seek(s, format.cbSize);
@@ -298,7 +307,7 @@ static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* c
        Stream_Write_UINT32(out, callback->formats_count); /* NumFormats (4 bytes) */
        Stream_Write_UINT32(out, cbSizeFormatsPacket); /* cbSizeFormatsPacket (4 bytes) */
        Stream_SetPosition(out, cbSizeFormatsPacket);
-       error = audin_channel_write_and_free(callback, out, TRUE);
+       error = audin_channel_write_and_free(callback, out, FALSE);
 out:
 
        if (error != CHANNEL_RC_OK)
@@ -315,6 +324,7 @@ out:
                }
        }
 
+       Stream_Free(out, TRUE);
        return error;
 }