diff --git a/api/baseapi.cpp b/api/baseapi.cpp index 3d51241834..0b80e4b967 100644 --- a/api/baseapi.cpp +++ b/api/baseapi.cpp @@ -1393,6 +1393,7 @@ static void AddBoxToTSV(const PageIterator* it, PageIteratorLevel level, * Image name/input_file_ can be set by SetInputName before calling * GetHOCRText * STL removed from original patch submission and refactored by rays. + * Returned string must be freed with the delete [] operator. */ char* TessBaseAPI::GetHOCRText(int page_number) { return GetHOCRText(NULL, page_number); @@ -1405,6 +1406,7 @@ char* TessBaseAPI::GetHOCRText(int page_number) { * Image name/input_file_ can be set by SetInputName before calling * GetHOCRText * STL removed from original patch submission and refactored by rays. + * Returned string must be freed with the delete [] operator. */ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) { if (tesseract_ == NULL || (page_res_ == NULL && Recognize(monitor) < 0)) diff --git a/api/baseapi.h b/api/baseapi.h index 5263b2d8d7..680b43eea4 100644 --- a/api/baseapi.h +++ b/api/baseapi.h @@ -591,6 +591,7 @@ class TESS_API TessBaseAPI { * monitor can be used to * cancel the recognition * receive progress callbacks + * Returned string must be freed with the delete [] operator. */ char* GetHOCRText(ETEXT_DESC* monitor, int page_number); @@ -598,6 +599,7 @@ class TESS_API TessBaseAPI { * Make a HTML-formatted string with hOCR markup from the internal * data structures. * page_number is 0-based but will appear in the output as 1-based. + * Returned string must be freed with the delete [] operator. */ char* GetHOCRText(int page_number); diff --git a/api/renderer.cpp b/api/renderer.cpp index ba370d9dcc..97e787a2a4 100644 --- a/api/renderer.cpp +++ b/api/renderer.cpp @@ -186,11 +186,10 @@ bool TessHOcrRenderer::EndDocumentHandler() { } bool TessHOcrRenderer::AddImageHandler(TessBaseAPI* api) { - char* hocr = api->GetHOCRText(imagenum()); + const std::unique_ptr hocr(api->GetHOCRText(imagenum())); if (hocr == NULL) return false; - AppendString(hocr); - delete[] hocr; + AppendString(hocr.get()); return true; }