Skip to content

Commit

Permalink
main: Fix two memory leaks
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stweil committed May 12, 2017
1 parent af212af commit f37f858
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/tesseractmain.cpp
Expand Up @@ -424,7 +424,9 @@ int main(int argc, char** argv) {
}

PERF_COUNT_START("Tesseract:main")
tesseract::TessBaseAPI api;

// Avoid memory leak caused by auto variable when exit() is called.
static tesseract::TessBaseAPI api;

api.SetOutputName(outputbase);

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

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

if (in_training_mode) {
renderers.push_back(NULL);
Expand Down

0 comments on commit f37f858

Please sign in to comment.