Skip to content

Commit

Permalink
RAII: pdfrenderer.cpp: buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
rfschtkt committed May 11, 2017
1 parent 936ca00 commit 3c6e18e
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions api/pdfrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,9 @@ bool TessPDFRenderer::BeginDocumentHandler() {
fseek(fp, 0, SEEK_END);
long int size = ftell(fp);
fseek(fp, 0, SEEK_SET);
char *buffer = new char[size];
if (fread(buffer, 1, size, fp) != size) {
const std::unique_ptr</*non-const*/ char[]> buffer(new char[size]);
if (fread(buffer.get(), 1, size, fp) != size) {
fclose(fp);
delete[] buffer;
return false;
}
fclose(fp);
Expand All @@ -685,13 +684,11 @@ bool TessPDFRenderer::BeginDocumentHandler() {
">>\n"
"stream\n", size, size);
if (n >= sizeof(buf)) {
delete[] buffer;
return false;
}
AppendString(buf);
objsize = strlen(buf);
AppendData(buffer, size);
delete[] buffer;
AppendData(buffer.get(), size);
objsize += size;
AppendString(endstream_endobj);
objsize += strlen(endstream_endobj);
Expand Down

0 comments on commit 3c6e18e

Please sign in to comment.