From 986970d6ca4f4d2035f7da2cb0bb11d1ac35fc83 Mon Sep 17 00:00:00 2001 From: Raf Schietekat Date: Wed, 10 May 2017 12:27:43 +0200 Subject: [PATCH] RAII: pdfrenderer.cpp: pdftext --- api/pdfrenderer.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/api/pdfrenderer.cpp b/api/pdfrenderer.cpp index d1574c5ae2..c388bb5af6 100644 --- a/api/pdfrenderer.cpp +++ b/api/pdfrenderer.cpp @@ -883,12 +883,11 @@ bool TessPDFRenderer::AddImageHandler(TessBaseAPI* api) { AppendPDFObject(buf); // CONTENTS - char* pdftext = GetPDFTextObjects(api, width, height); - long pdftext_len = strlen(pdftext); - unsigned char *pdftext_casted = reinterpret_cast(pdftext); + const std::unique_ptr pdftext(GetPDFTextObjects(api, width, height)); + const long pdftext_len = strlen(pdftext.get()); size_t len; unsigned char *comp_pdftext = - zlibCompress(pdftext_casted, pdftext_len, &len); + zlibCompress(reinterpret_cast(pdftext.get()), pdftext_len, &len); long comp_pdftext_len = len; n = snprintf(buf, sizeof(buf), "%ld 0 obj\n" @@ -897,7 +896,6 @@ bool TessPDFRenderer::AddImageHandler(TessBaseAPI* api) { ">>\n" "stream\n", obj_, comp_pdftext_len); if (n >= sizeof(buf)) { - delete[] pdftext; lept_free(comp_pdftext); return false; } @@ -906,7 +904,6 @@ bool TessPDFRenderer::AddImageHandler(TessBaseAPI* api) { AppendData(reinterpret_cast(comp_pdftext), comp_pdftext_len); objsize += comp_pdftext_len; lept_free(comp_pdftext); - delete[] pdftext; const char *b2 = "endstream\n" "endobj\n";