Ensure enc_frm_finish() is called on error paths in oapve_encode() - #295
Merged
kpchoi merged 1 commit intoSep 29, 2026
Merged
Conversation
kpchoi
requested changes
Sep 28, 2026
kpchoi
left a comment
Collaborator
There was a problem hiding this comment.
The fix looks correct: enc_frm_prepare() takes the references at its end, and all three error paths between it and enc_frm_finish() now release them.
Two small refinements are suggested.
- The
mid == NULLcheck is an argument check, so it can be done at the top ofoapve_encode(), before any frame is prepared. Then no cleanup is needed for it:
for(i = 0; i < ifrms->num_frms; i++) {
frm = &ifrms->frm[i];
if(ctx->use_frm_hash[i] &&
(frm->pbu_type == OAPV_PBU_TYPE_PRIMARY_FRAME || frm->pbu_type == OAPV_PBU_TYPE_NON_PRIMARY_FRAME)) {
oapv_assert_rv(mid != NULL, OAPV_ERR_INVALID_ARGUMENT);
}
}- The remaining two error paths can use the
oapv_assert_gv()/ERR:pattern that is used elsewhere in this file, instead of repeatingenc_frm_finish()andreturn:
ret = enc_frame(ctx, bs);
oapv_assert_gv(OAPV_SUCCEEDED(ret), ret, ret, ERR);
...
if(ctx->use_frm_hash[i]) {
if(frm->pbu_type == OAPV_PBU_TYPE_PRIMARY_FRAME ||
frm->pbu_type == OAPV_PBU_TYPE_NON_PRIMARY_FRAME) {
ret = oapv_set_md5_pld(mid, frm->group_id, ctx->imgb_r);
oapv_assert_gv(OAPV_SUCCEEDED(ret), ret, ret, ERR);
}
}
...
return OAPV_OK;
ERR:
enc_frm_finish(ctx, stat);
return ret;
}ERR: is reached only from inside the frame loop, after enc_frm_prepare() has succeeded, so enc_frm_finish() always releases exactly the references taken for the current frame.
Signed-off-by: Fyodor Kyslov <kyslov@google.com>
fkyslov
force-pushed
the
fix-enc-frm-finish-on-error
branch
from
September 28, 2026 17:58
e85fdfa to
cb71060
Compare
Contributor
Author
|
Updated per review feedback: moved the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ensures
enc_frm_finish()is called on error paths inoapve_encode()(src/oapv.c):imgbreference counts viaenc_frm_finish(ctx, stat)whenenc_frame()or MD5 payload insertion returns an error afterenc_frm_prepare().Testing
ctestunit/conformance tests pass with AddressSanitizer and UndefinedBehaviorSanitizer.