Skip to content

Commit f37f858

Browse files
committed
main: Fix two memory leaks
When Tesseract terminates by calling the exit function, the destructor of any local auto variable is not called. Fix two cases by using static variables. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent af212af commit f37f858

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

api/tesseractmain.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ int main(int argc, char** argv) {
424424
}
425425

426426
PERF_COUNT_START("Tesseract:main")
427-
tesseract::TessBaseAPI api;
427+
428+
// Avoid memory leak caused by auto variable when exit() is called.
429+
static tesseract::TessBaseAPI api;
428430

429431
api.SetOutputName(outputbase);
430432

@@ -493,7 +495,8 @@ int main(int argc, char** argv) {
493495
(api.GetBoolVariable("tessedit_resegment_from_boxes", &b) && b) ||
494496
(api.GetBoolVariable("tessedit_make_boxes_from_boxes", &b) && b);
495497

496-
tesseract::PointerVector<tesseract::TessResultRenderer> renderers;
498+
// Avoid memory leak caused by auto variable when exit() is called.
499+
static tesseract::PointerVector<tesseract::TessResultRenderer> renderers;
497500

498501
if (in_training_mode) {
499502
renderers.push_back(NULL);

0 commit comments

Comments
 (0)