[PR #1798] fix(ocr): add NULL checks and fix memory leaks #2536

Closed
opened 2026-01-29 17:22:39 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/1798

State: closed
Merged: Yes


Summary

  • search_language_pack: add NULL check after strdup(), fix unsafe realloc() that lost original pointer on failure
  • init_ocr: fix memory leak where ctx wasn't freed on early return when tessdata not found, add NULL checks for strdup() calls
  • ocr_bitmap: fix memory leak when pixCreate partially fails, add missing boxDestroy for crop_points on early return, add NULL checks for histogram/iot/mcit allocations, fix unsafe realloc() calls, add NULL check for text_out strdup
  • ocr_rect: add NULL check for copy allocation, initialize copy->data to NULL to prevent freep on uninitialized pointer, add NULL check for copy->data allocation
  • paraof_ocrtext: use fatal() on malloc failure for consistent OOM handling

All OOM conditions now use fatal(EXIT_NOT_ENOUGH_MEMORY, ...) following the project's coding patterns.

Test plan

  • Build succeeds
  • Run with OCR-enabled subtitle extraction to verify no regressions

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1798 **State:** closed **Merged:** Yes --- ## Summary - **search_language_pack**: add NULL check after strdup(), fix unsafe realloc() that lost original pointer on failure - **init_ocr**: fix memory leak where ctx wasn't freed on early return when tessdata not found, add NULL checks for strdup() calls - **ocr_bitmap**: fix memory leak when pixCreate partially fails, add missing boxDestroy for crop_points on early return, add NULL checks for histogram/iot/mcit allocations, fix unsafe realloc() calls, add NULL check for text_out strdup - **ocr_rect**: add NULL check for copy allocation, initialize copy->data to NULL to prevent freep on uninitialized pointer, add NULL check for copy->data allocation - **paraof_ocrtext**: use fatal() on malloc failure for consistent OOM handling All OOM conditions now use `fatal(EXIT_NOT_ENOUGH_MEMORY, ...)` following the project's coding patterns. ## Test plan - [x] Build succeeds - [ ] Run with OCR-enabled subtitle extraction to verify no regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claunia added the pull-request label 2026-01-29 17:22:39 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2536