mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-07-08 18:06:30 +00:00
fix(hardsubx): Fix memory leaks in hardsubx processing
- Free basefilename in _dinit_hardsubx (allocated by get_basename) - Free subtitle_text after each frame processing iteration - Free prev_subtitle_text when replaced and at end of function - Free sws_ctx with sws_freeContext (was never freed) Reduces memory leaks from 63,926 bytes to 0 bytes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -121,6 +121,8 @@ int hardsubx_process_data(struct lib_hardsubx_ctx *ctx, struct lib_ccx_ctx *ctx_
|
||||
|
||||
// Free the allocated memory for frame processing
|
||||
av_free(ctx->rgb_buffer);
|
||||
if (ctx->sws_ctx)
|
||||
sws_freeContext(ctx->sws_ctx);
|
||||
if (ctx->frame)
|
||||
av_frame_free(&ctx->frame);
|
||||
if (ctx->rgb_frame)
|
||||
@@ -336,6 +338,9 @@ void _dinit_hardsubx(struct lib_hardsubx_ctx **ctx)
|
||||
TessBaseAPIEnd(lctx->tess_handle);
|
||||
TessBaseAPIDelete(lctx->tess_handle);
|
||||
|
||||
// Free basefilename (allocated by get_basename in _init_hardsubx)
|
||||
freep(&lctx->basefilename);
|
||||
|
||||
// Free subtitle
|
||||
freep(&lctx->dec_sub);
|
||||
freep(ctx);
|
||||
|
||||
@@ -210,6 +210,7 @@ void hardsubx_process_frames_linear(struct lib_hardsubx_ctx *ctx, struct encoder
|
||||
if (dist < (0.2 * MIN(strlen(subtitle_text), strlen(prev_subtitle_text))))
|
||||
{
|
||||
dist = -1;
|
||||
free(subtitle_text);
|
||||
subtitle_text = NULL;
|
||||
prev_end_time = convert_pts_to_ms(ctx->packet.pts, ctx->format_ctx->streams[ctx->video_stream_id]->time_base);
|
||||
}
|
||||
@@ -219,6 +220,7 @@ void hardsubx_process_frames_linear(struct lib_hardsubx_ctx *ctx, struct encoder
|
||||
add_cc_sub_text(ctx->dec_sub, prev_subtitle_text, prev_begin_time, prev_end_time, "", "BURN", CCX_ENC_UTF_8);
|
||||
encode_sub(enc_ctx, ctx->dec_sub);
|
||||
prev_begin_time = prev_end_time + 1;
|
||||
free(prev_subtitle_text);
|
||||
prev_subtitle_text = NULL;
|
||||
prev_sub_encoded = 1;
|
||||
prev_end_time = convert_pts_to_ms(ctx->packet.pts, ctx->format_ctx->streams[ctx->video_stream_id]->time_base);
|
||||
@@ -252,6 +254,10 @@ void hardsubx_process_frames_linear(struct lib_hardsubx_ctx *ctx, struct encoder
|
||||
prev_sub_encoded = 0;
|
||||
}
|
||||
prev_packet_pts = ctx->packet.pts;
|
||||
|
||||
// Free subtitle_text from this iteration (was allocated by _process_frame_*_basic)
|
||||
free(subtitle_text);
|
||||
subtitle_text = NULL;
|
||||
}
|
||||
}
|
||||
av_packet_unref(&ctx->packet);
|
||||
@@ -263,6 +269,9 @@ void hardsubx_process_frames_linear(struct lib_hardsubx_ctx *ctx, struct encoder
|
||||
encode_sub(enc_ctx, ctx->dec_sub);
|
||||
prev_sub_encoded = 1;
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
free(prev_subtitle_text);
|
||||
activity_progress(100, cur_sec / 60, cur_sec % 60);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user