From 957737276037ff071b2a945e768d8c54c6a67b1d Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 26 Aug 2024 15:16:41 +0200 Subject: [PATCH] vcomp/cmpto_j2k: if enc fails, free data We need to release the resources if encode fails - otherwise eg. the pool will get exhausted because it has a limited capacity. + print enc image failure whether was in push or pop --- src/video_compress/cmpto_j2k.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/video_compress/cmpto_j2k.cpp b/src/video_compress/cmpto_j2k.cpp index 71c163dde..697fb245a 100644 --- a/src/video_compress/cmpto_j2k.cpp +++ b/src/video_compress/cmpto_j2k.cpp @@ -270,10 +270,9 @@ static std::shared_ptr j2k_compress_pop(struct module *state) struct cmpto_j2k_enc_img *img; int status; CHECK_OK(cmpto_j2k_enc_ctx_get_encoded_img( - s->context, - 1, - &img /* Set to NULL if encoder stopped */, - &status), "Encode image", HANDLE_ERROR_COMPRESS_POP); + s->context, 1, &img /* Set to NULL if encoder stopped */, + &status), + "Encode image pop", HANDLE_ERROR_COMPRESS_POP); { unique_lock lk(s->lock); s->in_frames--; @@ -516,8 +515,14 @@ static void j2k_compress_push(struct module *state, std::shared_ptr unique_lock lk(s->lock); s->frame_popped.wait(lk, [s]{return s->in_frames < s->max_in_frames;}); lk.unlock(); + bool failed = false; CHECK_OK(cmpto_j2k_enc_img_encode(img, s->enc_settings), - "Encode image", return); + "Encode image push", failed = true); + if (failed) { + udata->frame.~shared_ptr(); + cmpto_j2k_enc_img_destroy(img); + return; + } lk.lock(); s->in_frames++; lk.unlock();