diff --git a/api/baseapi.cpp b/api/baseapi.cpp index dda99883f..473df8a50 100644 --- a/api/baseapi.cpp +++ b/api/baseapi.cpp @@ -1702,8 +1702,9 @@ const int kMaxBytesPerLine = kNumbersPerBlob * (kBytesPer64BitNumber + 1) + 1 + /** * The recognized text is returned as a char* which is coded - * as a UTF8 box file and must be freed with the delete [] operator. + * as a UTF8 box file. * page_number is a 0-base page index that will appear in the box file. + * Returned string must be freed with the delete [] operator. */ char* TessBaseAPI::GetBoxText(int page_number) { if (tesseract_ == NULL || diff --git a/api/baseapi.h b/api/baseapi.h index b78206f85..0b473e291 100644 --- a/api/baseapi.h +++ b/api/baseapi.h @@ -612,10 +612,10 @@ class TESS_API TessBaseAPI { /** * The recognized text is returned as a char* which is coded in the same - * format as a box file used in training. Returned string must be freed with - * the delete [] operator. + * format as a box file used in training. * Constructs coordinates in the original image - not just the rectangle. * page_number is a 0-based page index that will appear in the box file. + * Returned string must be freed with the delete [] operator. */ char* GetBoxText(int page_number); diff --git a/api/renderer.cpp b/api/renderer.cpp index 97273f3cd..2dc274da5 100644 --- a/api/renderer.cpp +++ b/api/renderer.cpp @@ -251,11 +251,10 @@ TessBoxTextRenderer::TessBoxTextRenderer(const char *outputbase) } bool TessBoxTextRenderer::AddImageHandler(TessBaseAPI* api) { - char* text = api->GetBoxText(imagenum()); + const std::unique_ptr text(api->GetBoxText(imagenum())); if (text == NULL) return false; - AppendString(text); - delete[] text; + AppendString(text.get()); return true; }