Skip to content

Commit

Permalink
whisper : fix potential memory leaks (ggerganov#740)
Browse files Browse the repository at this point in the history
* fix potential memory leak if whisper_init_state failed

* fix potential memory leak if gpt2_init failed
  • Loading branch information
baderouaich authored Apr 14, 2023
1 parent 7727a40 commit 2c856fb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/talk.wasm/gpt-2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ struct gpt2_context * gpt2_init(const char * path_model) {

if (!gpt2_model_load(path_model, ctx->model, ctx->vocab)) {
fprintf(stderr, "%s: failed to load model from '%s'\n", __func__, "gpt-2.bin");
delete ctx;
return nullptr;
}

Expand Down
2 changes: 2 additions & 0 deletions whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2487,6 +2487,7 @@ struct whisper_state * whisper_init_state(whisper_context * ctx) {

if (!kv_cache_init(ctx->model.hparams, scale * MEM_REQ_KV_SELF.at(ctx->model.type), state->decoders[0].kv_self, ctx->wtype, ctx->model.hparams.n_text_ctx)) {
fprintf(stderr, "%s: kv_cache_init() failed for self-attention cache\n", __func__);
delete state;
return nullptr;
}

Expand All @@ -2497,6 +2498,7 @@ struct whisper_state * whisper_init_state(whisper_context * ctx) {

if (!kv_cache_init(ctx->model.hparams, scale * MEM_REQ_KV_CROSS.at(ctx->model.type), state->kv_cross, ctx->wtype, ctx->model.hparams.n_audio_ctx)) {
fprintf(stderr, "%s: kv_cache_init() failed for cross-attention cache\n", __func__);
delete state;
return nullptr;
}

Expand Down

0 comments on commit 2c856fb

Please sign in to comment.