Commit 0089cb39 for tesseract
commit 0089cb3967659a404b33eb3a251cbb31ac2b5742
Author: Stefan Weil <sw@weilnetz.de>
Date: Tue Dec 1 17:02:17 2026 +0100
Fix memory leak in GridRemoveUnderlinePartitions
ColumnFinder::GridRemoveUnderlinePartitions deletes a partition which
was made from the blobs of a horizontal line if that line looks like
an underline. The blobs kept the deleted partition as their owner.
ReleaseBlobsAndCleanupUnused only deletes the blobs without an owner
and removes the others from the lists of the block, so nothing was
left which could delete these blobs:
ERROR: LeakSanitizer: detected memory leaks
Direct leak of 152 byte(s) in 1 object(s) allocated from:
#1 tesseract::assign_blobs_to_blocks2(...)
src/textord/tordmain.cpp:196:22
OSS-Fuzz found that with fuzzer-raw-image (issue 591167217).
Disown the blobs before the partition is deleted, as
ColPartitionGrid::DeleteUnknownParts does. They no longer point to a
deleted partition, and ReleaseBlobsAndCleanupUnused deletes them.
Assisted-by: Claude Fable 5.2 (Anthropic)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
diff --git a/src/textord/colfind.cpp b/src/textord/colfind.cpp
index a234dda8..ab275db7 100644
--- a/src/textord/colfind.cpp
+++ b/src/textord/colfind.cpp
@@ -1272,6 +1272,9 @@ void ColumnFinder::GridRemoveUnderlinePartitions() {
}
if (line_part != nullptr && !touched_table && touched_text) {
part_grid_.RemoveBBox(line_part);
+ // The blobs of the partition are still in the lists of the block.
+ // Without an owner they are deleted by ReleaseBlobsAndCleanupUnused.
+ line_part->DisownBoxes();
delete line_part;
}
}