From 78142593d24edcf9fcc7fc83e14d39733b55aa41 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 13 May 2017 11:34:40 +0200 Subject: [PATCH] Fix order of destructor calls for DawgCache and TessBaseAPI TessBaseAPI must release its cache use before DawgCache is destroyed. Signed-off-by: Stefan Weil --- api/tesseractmain.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/tesseractmain.cpp b/api/tesseractmain.cpp index 4d644bacb..f1fe2fb9b 100644 --- a/api/tesseractmain.cpp +++ b/api/tesseractmain.cpp @@ -27,6 +27,7 @@ #include "allheaders.h" #include "baseapi.h" #include "basedir.h" +#include "dict.h" #include "openclwrapper.h" #include "osdetect.h" #include "renderer.h" @@ -425,6 +426,11 @@ int main(int argc, char** argv) { PERF_COUNT_START("Tesseract:main") + // Call GlobalDawgCache here to create the global DawgCache object before + // the TessBaseAPI object. This fixes the order of destructor calls: + // first TessBaseAPI must be destructed, DawgCache must be the last object. + tesseract::Dict::GlobalDawgCache(); + // Avoid memory leak caused by auto variable when exit() is called. static tesseract::TessBaseAPI api;