* vad : fix memory leak by storing ggml_context in vad context struct
This commit addresses a memory leak issue in the voice activity
detection (VAD) where the ggml_context is not stored within the vad
context structure.
The motivation for this change that this is causing the context memory
to stay allocated and the tensor still point to that memory but this
memory is never freed.
* vad : free memory allocated for VAD hparams
This commit frees the model hyperparameters allocated for the VAD
context in the `whisper_vad_free` function. Specifically, it deletes the
`encoder_in_channels`, `encoder_out_channels`, and `kernel_sizes` arrays
allocated with `new[]` in the `whisper_vad_init` function.
The motivation for this is to prevent memory leaks when the VAD.
* vad: free ggml buffer in whisper_vad_free
This commit frees the ggml buffer in the whisper_vad_free function to
prevent memory leaks.
Resolves: https://github.com/ggml-org/whisper.cpp/issues/3452
* Revert "vad : fix memory leak by storing ggml_context in vad context struct"
This reverts commit
aeafca437efa7fb28166703f845e321176aa62ab.
* whisper : free ggml context in whisper_vad_init_context
This commit frees the ggml_context after initializing the VAD context in
the whisper_vad_init_context function.
The motivation for this is to prevent memory leaks.
ggml_set_name(vctx->c_state, "c_state");
vctx->buffer = ggml_backend_alloc_ctx_tensors(ctx, vctx->backends[0]);
+ ggml_free(ctx);
if (!vctx->buffer) {
WHISPER_LOG_ERROR("%s: failed to allocate memory for the VAD state\n", __func__);
return false;
void whisper_vad_free(whisper_vad_context * ctx) {
if (ctx) {
+ if (ctx->buffer) {
+ ggml_backend_buffer_free(ctx->buffer);
+ }
for (ggml_context * context : ctx->model.ctxs) {
ggml_free(context);
}
ggml_backend_free(backend);
}
+ delete[] ctx->model.hparams.encoder_in_channels;
+ delete[] ctx->model.hparams.encoder_out_channels;
+ delete[] ctx->model.hparams.kernel_sizes;
delete ctx;
}