Skip to content

Commit 6fad5fc

Browse files
committed
dict/dict: Fix memory leaks at program termination
Avoid dynamic memory allocation for the static variable 'cache'. Now the destructor for that variable is called automatically when Tesseract terminates and releases all associated memory. Signed-off-by: Stefan Weil <[email protected]>
1 parent 55bcfb5 commit 6fad5fc

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

dict/dict.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,10 @@ Dict::~Dict() {
184184
}
185185

186186
DawgCache *Dict::GlobalDawgCache() {
187-
// We dynamically allocate this global cache (a singleton) so it will outlive
188-
// every Tesseract instance (even those that someone else might declare as
189-
// global statics).
190-
static DawgCache *cache = new DawgCache(); // evil global singleton
191-
return cache;
187+
// This global cache (a singleton) will outlive every Tesseract instance
188+
// (even those that someone else might declare as global statics).
189+
static DawgCache cache;
190+
return &cache;
192191
}
193192

194193
void Dict::Load(DawgCache *dawg_cache) {

0 commit comments

Comments
 (0)