Commit 81085416 for tesseract
commit 810854166ed6382fcf0efe1a2e87b9333e41b930
Author: Stefan Weil <sw@weilnetz.de>
Date: Sun Aug 9 13:18:42 2026 +0200
Fix CID 1660576 (Resource leak)
Use a unique_ptr for the local PARA object and transfer ownership
explicitly with release() when storing it in row_owners.
Assisted-by: OpenCode / big-pickle (opencode)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
diff --git a/src/ccmain/paragraphs.cpp b/src/ccmain/paragraphs.cpp
index 12866ebc..39aaa3e4 100644
--- a/src/ccmain/paragraphs.cpp
+++ b/src/ccmain/paragraphs.cpp
@@ -2111,7 +2111,7 @@ static void ConvertHypothesizedModelRunsToParagraphs(std::vector<RowScratchRegis
continue;
}
// rows[start, end) should be a paragraph.
- PARA *p = new PARA();
+ std::unique_ptr<PARA> p(new PARA());
if (model == kCrownLeft || model == kCrownRight) {
p->is_very_first_or_continuation = true;
// Crown paragraph.
@@ -2148,6 +2148,7 @@ static void ConvertHypothesizedModelRunsToParagraphs(std::vector<RowScratchRegis
p->is_list_item = model->justification() == JUSTIFICATION_RIGHT
? rows[start].ri_->rword_indicates_list_item
: rows[start].ri_->lword_indicates_list_item;
+ PARA *para = p.release();
for (int row = start; row < end; row++) {
if ((*row_owners)[row] != nullptr) {
tprintf(
@@ -2155,7 +2156,7 @@ static void ConvertHypothesizedModelRunsToParagraphs(std::vector<RowScratchRegis
"more than once!\n");
delete (*row_owners)[row];
}
- (*row_owners)[row] = p;
+ (*row_owners)[row] = para;
}
}
}