Conversation
Added error handling for memory allocation and codec initialization in hardsubx_process_data function.
Added comment to clarify the purpose of the hardsubx function.
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit f377be9...:
Congratulations: Merging this PR would fix the following tests:
All tests passed completely. Check the result page for more info. |
CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit f377be9...:
Your PR breaks these cases:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
cfsmp3
left a comment
There was a problem hiding this comment.
The real fixes here are good (missing return, TessBaseAPIDelete leaks in _init_hardsubx, NULL checks for av_malloc/sws_getContext/init_encoder). But the PR introduces a lot of dead code.
fatal() calls exit() — it never returns. Every goto cleanup placed after a fatal() call is unreachable dead code. Same for the return NULL statements placed after fatal() in _init_hardsubx(). Please remove all of that.
For the new NULL checks (av_malloc, sws_getContext, init_encoder), just use fatal() directly like the rest of the function does — no goto needed.
Also:
- Squash the 4 commits into one.
- Remove the CHANGES.TXT entry — this is an internal code quality fix, not a user-facing change.
[FIX] Fix resource leaks, missing NULL checks, and missing return in hardsubx.c
In raising this pull request, I confirm the following (please check boxes):
My familiarity with the project is as follows (check one):
What does this PR do?
Fixes several error-handling issues in
src/lib_ccx/hardsubx.cacross both_init_hardsubx()andhardsubx_process_data().Changes in
_init_hardsubx()Added NULL check for
TessBaseAPICreate(): The return value was never validated. If it returned NULL, every subsequent Tesseract call would hit undefined behavior.Added NULL checks for both
strdup()calls:pars_vecandpars_valueswere used without checking ifstrdup()succeeded. On memory allocation failure these would be NULL pointers passed intoTessBaseAPIInit4().Added
TessBaseAPIDelete()in error paths: Whentessdata_pathlookup failed orTessBaseAPIInit4()returned non-zero, the code calledfree(ctx)without first deleting the Tesseract handle that was already created. This leaked the handle every time one of these error paths was hit.Changes in
hardsubx_process_data()Added missing return statement: The function is declared as returning
intbut never actually returned a value, which is undefined behavior per the C standard.Added NULL checks for
av_malloc(),sws_getContext(), andinit_encoder(): All three can return NULL on failure, but the results were being used directly without any validation.Replaced per-error cleanup with
goto cleanuppattern: Previously, eachfatal()call would exit without freeing any of the FFmpeg resources allocated up to that point (codec context, format context, frames, buffers, etc.). Now all error paths jump to a centralized cleanup section that safely frees everything that was allocated.Issues Fixed
Fixes #2158
Fixes #2160
Fixes #2161
Testing
free(NULL)is a no-op per the C standard,av_frame_free()andavcodec_free_context()handle NULL pointers )