Skip to content

Commit b7b68a6

Browse files
committed
RAII: *::GetTSVText()
1 parent a1fff87 commit b7b68a6

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

api/baseapi.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
15771577
/**
15781578
* Make a TSV-formatted string from the internal data structures.
15791579
* page_number is 0-based but will appear in the output as 1-based.
1580+
* Returned string must be freed with the delete [] operator.
15801581
*/
15811582
char* TessBaseAPI::GetTSVText(int page_number) {
15821583
if (tesseract_ == NULL || (page_res_ == NULL && Recognize(NULL) < 0))

api/baseapi.h

+1
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ class TESS_API TessBaseAPI {
606606
/**
607607
* Make a TSV-formatted string from the internal data structures.
608608
* page_number is 0-based but will appear in the output as 1-based.
609+
* Returned string must be freed with the delete [] operator.
609610
*/
610611
char* GetTSVText(int page_number);
611612

api/renderer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,10 @@ bool TessTsvRenderer::BeginDocumentHandler() {
218218
bool TessTsvRenderer::EndDocumentHandler() { return true; }
219219

220220
bool TessTsvRenderer::AddImageHandler(TessBaseAPI* api) {
221-
char* tsv = api->GetTSVText(imagenum());
221+
const std::unique_ptr<const char[]> tsv(api->GetTSVText(imagenum()));
222222
if (tsv == NULL) return false;
223223

224-
AppendString(tsv);
225-
delete[] tsv;
224+
AppendString(tsv.get());
226225

227226
return true;
228227
}

0 commit comments

Comments
 (0)