]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
vad : free vad_segments in whisper_vad (#3463)
authorSilviu Caragea <redacted>
Fri, 10 Oct 2025 04:20:21 +0000 (04:20 +0000)
committerGitHub <redacted>
Fri, 10 Oct 2025 04:20:21 +0000 (06:20 +0200)
This commit fixes multiple issues:

* memory leak because vad_segments is never released
* avoid segmentation fault when whisper_vad_segments_from_samples returns nullptr.
* avoid potential segmentation fault when the app fails to allocate memory for filtered samples and the vad context is released but also get released withing state itself when whisper_free_state is called

src/whisper.cpp

index a49eb59aa6252fc19e94bca5880a8b4c9b50a9da..8992a144e2da1cd21f724803e99254bd45a87052 100644 (file)
@@ -6620,6 +6620,9 @@ static bool whisper_vad(
 
     whisper_vad_segments * vad_segments = whisper_vad_segments_from_samples(vctx, vad_params, samples, n_samples);
 
+    if(!vad_segments)
+        return false;
+
     if (vad_segments->data.size() > 0) {
         state->has_vad_segments = true;
         ctx->state->vad_segments.clear();
@@ -6662,7 +6665,6 @@ static bool whisper_vad(
         } catch (const std::bad_alloc & /* e */) {
             WHISPER_LOG_ERROR("%s: failed to allocate memory for filtered samples\n", __func__);
             whisper_vad_free_segments(vad_segments);
-            whisper_vad_free(vctx);
             return false;
         }
 
@@ -6768,6 +6770,7 @@ static bool whisper_vad(
                         __func__, n_samples, filtered_n_samples, 100.0f * (1.0f - (float)filtered_n_samples / n_samples));
     }
 
+    whisper_vad_free_segments(vad_segments);
     return true;
 }