0

Working on memory leaks, just faced that valgrind memcheck sees serious leak on TessBaseAPI initialization call.

Update: official Tess Sample gets warning from valgrind https://tesseract-ocr.github.io/tessdoc/Examples_C++.html

api4->Init

is there any way to fix this?

 void Name::test(){
tesseract::TessBaseAPI *apiUnique = new tesseract::TessBaseAPI();
apiUnique->Init("/usr/share/tesseract-ocr/4.00/tessdata/", "eng");
outText = apiUnique->GetUTF8Text();
apiUnique->Clear();
apiUnique->End();

delete [] outText;
delete  apiUnique;

}

==15652== Conditional jump or move depends on uninitialised value(s)
==15652==    at 0xA49B60D: nextOnPixelInRaster (in /usr/lib/x86_64-linux-gnu/liblept.so.5.0.4)
==15652==    by 0xA49C85D: pixConnCompBB (in /usr/lib/x86_64-linux-gnu/liblept.so.5.0.4)
==15652==    by 0xA450E80: ??? (in /usr/lib/x86_64-linux-gnu/liblept.so.5.0.4)
==15652==    by 0xA451494: ??? (in /usr/lib/x86_64-linux-gnu/liblept.so.5.0.4)
==15652==    by 0xA451EFA: bmfCreate (in /usr/lib/x86_64-linux-gnu/liblept.so.5.0.4)
==15652==    by 0x57965BF: tesseract::Tesseract::Tesseract() (in /usr/lib/x86_64-linux-gnu/libtesseract.so.4.0.1)
==15652==    by 0x574E396: tesseract::TessBaseAPI::Init(char const*, int, char const*, tesseract::OcrEngineMode, char**, int, GenericVector<STRING> const*, GenericVector<STRING> const*, bool, bool (*)(STRING const&, GenericVector<char>*)) (in /usr/lib/x86_64-linux-gnu/libtesseract.so.4.0.1)
==15652==    by 0x574E7C9: tesseract::TessBaseAPI::Init(char const*, char const*, tesseract::OcrEngineMode, char**, int, GenericVector<STRING> const*, GenericVector<STRING> const*, bool) (in /usr/lib/x86_64-linux-gnu/libtesseract.so.4.0.1)
==15652==    by 0x14B528: tesseract::TessBaseAPI::Init(char const*, char const*) (baseapi.h:224)
==15652==    by 0x14B225: Name::test() (Name.cpp:64)
==15652==    by 0x184A70: main (main.cpp:69)
  • In all likelyhood you forgot to delete `api4` somewhere. A good way to get rid of memory leaks is to not use raw "new/delete" anymore. E.g. replace your `new` with `std::make_unique()`. – Pepijn Kramer Jul 27 '23 at 04:17
  • Side note have a look at [C++ core guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) specialy rule R.11 – Pepijn Kramer Jul 27 '23 at 04:19
  • Pepjin Kramer, thanks for reply, but after I rename api name to unique and delete -> same issue, set to NULL no effect either – JamesQReader Jul 27 '23 at 06:36
  • I just had a quick look at the documentation (I never used that libaray). I think you should do the same. https://tesseract-ocr.github.io/tessapi/3.x/a01281.html#ga38027513ee9c0348de1790bddcdc3391. Specialy the part about calling `End()` – Pepijn Kramer Jul 27 '23 at 06:46
  • ==6922== Conditional jump or move depends on uninitialised value(s) / same issue after I've added apiUnique->End(); before delete apiUnique – JamesQReader Jul 27 '23 at 06:51

0 Answers0