From: Silviu Caragea Date: Fri, 10 Oct 2025 04:20:21 +0000 (+0000) Subject: vad : free vad_segments in whisper_vad (#3463) X-Git-Tag: upstream/1.8.2~65 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=85d1d3d3dcd6e95944920ddb7ef30a016f6c5b22;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp vad : free vad_segments in whisper_vad (#3463) 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 --- diff --git a/src/whisper.cpp b/src/whisper.cpp index a49eb59a..8992a144 100644 --- a/src/whisper.cpp +++ b/src/whisper.cpp @@ -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; }