Skip to content

[BUG] hardsubx_process_data() has no return statement, missing NULL checks, and leaks resources on error #2161

@SuvidhJ

Description

@SuvidhJ

There are several issues in hardsubx_process_data() in src/lib_ccx/hardsubx.c:

  1. No return statement. The function is declared as int but never returns anything. This will lead to undefined behavior if the caller ever tries to use the return value.

  2. av_malloc() result is not checked . If allocation fails, the NULL pointer gets passed into av_image_fill_arrays() and later into frame processing. This might cause segfault.

  3. sws_getContext() result is not checked. The code checks for NULL before calling sws_freeContext() at the end, but never checks after creation. The code doesn't guard against it even after possibility of NULL

  4. init_encoder() result is not checked. The pointer goes into the processing functions and dinit_encoder() without any validation.

  5. Resource leaks in error paths. Every fatal() call in the function just exits without cleaning up whatever was allocated before that point. For example, if avcodec_open2() fails, codec_ctx and format_ctx are leaked. If av_frame_alloc() fails, add frames to that list, etc.

Suggested fix:

  • Use of a goto cleanup pattern with a centralized cleanup section at the end of the function. This avoids repeating cleanup code in every error path and makes it easy to add new allocations later without forgetting to clean them up.
  • add the missing NULL checks and a proper return value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions