Skip to content

Commit

Permalink
api/tesseractmain: Fix memory leak caused by exit()
Browse files Browse the repository at this point in the history
When exit() is called from ParseArgs(), no destructors are executed
for the auto variables vars_vec and vars_values.

Making both variables static fixes the memory leaks, because now the
destructors are always executed.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Oct 24, 2016
1 parent 53c572b commit f1d3a3b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/tesseractmain.cpp
Expand Up @@ -358,16 +358,22 @@ void PreloadRenderers(tesseract::TessBaseAPI* api,
* main()
*
**********************************************************************/


int main(int argc, char **argv) {
const char* lang = "eng";
const char* image = NULL;
const char* outputbase = NULL;
const char* datapath = NULL;
bool list_langs = false;
bool print_parameters = false;
GenericVector<STRING> vars_vec, vars_values;
int arg_i = 1;
tesseract::PageSegMode pagesegmode = tesseract::PSM_AUTO;
/* main() calls functions like ParseArgs which call exit().
* This results in memory leaks if vars_vec and vars_values are
* declared as auto variables (destructor is not called then). */
static GenericVector<STRING> vars_vec;
static GenericVector<STRING> vars_values;

#if defined(HAVE_TIFFIO_H) && defined(_WIN32)
/* Show libtiff warnings on console (not in GUI). */
Expand Down

0 comments on commit f1d3a3b

Please sign in to comment.