From f1d3a3b7c347257bf22c7116a913bda185227fae Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 24 Oct 2016 20:18:39 +0200 Subject: [PATCH] api/tesseractmain: Fix memory leak caused by exit() 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 --- api/tesseractmain.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/tesseractmain.cpp b/api/tesseractmain.cpp index 798888fc..3fe8dc8c 100644 --- a/api/tesseractmain.cpp +++ b/api/tesseractmain.cpp @@ -358,6 +358,8 @@ void PreloadRenderers(tesseract::TessBaseAPI* api, * main() * **********************************************************************/ + + int main(int argc, char **argv) { const char* lang = "eng"; const char* image = NULL; @@ -365,9 +367,13 @@ int main(int argc, char **argv) { const char* datapath = NULL; bool list_langs = false; bool print_parameters = false; - GenericVector 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 vars_vec; + static GenericVector vars_values; #if defined(HAVE_TIFFIO_H) && defined(_WIN32) /* Show libtiff warnings on console (not in GUI). */