Quellcode durchsuchen

test/testautomation_audio.c: Free variables before returning

Petar Popovic vor 2 Monaten
Ursprung
Commit
da2460f9e7
1 geänderte Dateien mit 15 neuen und 0 gelöschten Zeilen
  1. 15 0
      test/testautomation_audio.c

+ 15 - 0
test/testautomation_audio.c

@@ -809,6 +809,7 @@ static int SDLCALL audio_convertAudio(void *arg)
                         src_buf = (Uint8 *)SDL_malloc(src_len);
                         SDLTest_AssertCheck(src_buf != NULL, "Check src data buffer to convert is not NULL");
                         if (src_buf == NULL) {
+                            SDL_DestroyAudioStream(stream);
                             return TEST_ABORTED;
                         }
 
@@ -819,6 +820,8 @@ static int SDLCALL audio_convertAudio(void *arg)
                         dst_buf = (Uint8 *)SDL_malloc(dst_len);
                         SDLTest_AssertCheck(dst_buf != NULL, "Check dst data buffer to convert is not NULL");
                         if (dst_buf == NULL) {
+                            SDL_DestroyAudioStream(stream);
+                            SDL_free(src_buf);
                             return TEST_ABORTED;
                         }
 
@@ -828,6 +831,9 @@ static int SDLCALL audio_convertAudio(void *arg)
                         /* Run the audio converter */
                         if (!SDL_PutAudioStreamData(stream, src_buf, src_len) ||
                             !SDL_FlushAudioStream(stream)) {
+                            SDL_DestroyAudioStream(stream);
+                            SDL_free(src_buf);
+                            SDL_free(dst_buf);
                             return TEST_ABORTED;
                         }
 
@@ -837,6 +843,9 @@ static int SDLCALL audio_convertAudio(void *arg)
                         real_dst_len = SDL_GetAudioStreamData(stream, dst_buf, dst_len);
                         SDLTest_AssertCheck(dst_len == real_dst_len, "Verify result value; expected: %i; got: %i", dst_len, real_dst_len);
                         if (dst_len != real_dst_len) {
+                            SDL_DestroyAudioStream(stream);
+                            SDL_free(src_buf);
+                            SDL_free(dst_buf);
                             return TEST_ABORTED;
                         }
 
@@ -848,6 +857,9 @@ static int SDLCALL audio_convertAudio(void *arg)
                         for (m = 0; m < dst_len; ++m) {
                             if (dst_buf[m] != dst_silence) {
                                 SDLTest_LogError("Output buffer is not silent");
+                                SDL_DestroyAudioStream(stream);
+                                SDL_free(src_buf);
+                                SDL_free(dst_buf);
                                 return TEST_ABORTED;
                             }
                         }
@@ -1104,6 +1116,7 @@ static int SDLCALL audio_resampleLoss(void *arg)
     SDLTest_AssertCheck(buf_out != NULL, "Expected output buffer to be created.");
     if (buf_out == NULL) {
       SDL_DestroyAudioStream(stream);
+      SDL_free(buf_in);
       return TEST_ABORTED;
     }
 
@@ -1114,6 +1127,7 @@ static int SDLCALL audio_resampleLoss(void *arg)
     SDL_free(buf_in);
     if (len_out != len_target) {
       SDL_DestroyAudioStream(stream);
+      SDL_free(buf_out);
       return TEST_ABORTED;
     }
 
@@ -1130,6 +1144,7 @@ static int SDLCALL audio_resampleLoss(void *arg)
             sum_squared_value += target * target;
         }
     }
+    SDL_DestroyAudioStream(stream);
     SDL_free(buf_out);
     signal_to_noise = 10 * SDL_log10(sum_squared_value / sum_squared_error); /* decibel */
     SDLTest_AssertCheck(ISFINITE(sum_squared_value), "Sum of squared target should be finite.");