Commit 83010e9f for tesseract
commit 83010e9f7780896e1bc8c17e6800ad8d1b013fa8
Author: Stefan Weil <sw@weilnetz.de>
Date: Thu Nov 12 19:10:06 2026 +0100
fuzzer: delete the API on exit and include cstdint
Add a LLVMFuzzerDone() hook that releases the API, so its legacy
dictionary does not keep DAWG references in the static global DAWG
cache that leak at teardown. Also include <cstdint> for uint8_t.
Assisted-by: OpenCode / qwen3.8-27b-thinking (Alibaba Cloud)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
diff --git a/unittest/fuzzers/fuzzer-api.cpp b/unittest/fuzzers/fuzzer-api.cpp
index c17886e3..7d577cd6 100644
--- a/unittest/fuzzers/fuzzer-api.cpp
+++ b/unittest/fuzzers/fuzzer-api.cpp
@@ -2,6 +2,7 @@
#include <tesseract/baseapi.h>
#include <libgen.h> // for dirname
+#include <cstdint> // for uint8_t
#include <cstdio> // for printf
#include <cstdlib> // for std::getenv, std::setenv
#include <string> // for std::string
@@ -104,3 +105,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;
}
+
+// Release the API on exit (called by libFuzzer). Without this, the API's
+// legacy dictionary keeps references to the DAWGs of the static global DAWG
+// cache (Dict::GlobalDawgCache()), which still hold count > 0 when that cache
+// is destroyed during static teardown, printing spurious
+// "ObjectCache: WARNING! LEAK!" lines. Deleting the API runs the normal
+// ~Tesseract() -> Dict::End() path, which releases the references.
+extern "C" void LLVMFuzzerDone() {
+ delete api;
+ api = nullptr;
+}