summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Deherly <nicolas.deherly@navblue.aero>2020-09-28 16:30:30 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-09-28 17:37:09 +0000
commit77c489ed4ceb490f33b805e7ba4cd34ef9191db7 (patch)
tree359e3e865442d0ccc67030f11b50e3f35c98fe99
parent3bf3d3fe7bcfa7933ecc2ec2f1607f586b2b00d8 (diff)
Fix memory management in QPdfDocument functionsHEADdev
All pages that are opened have to be closed, in order to avoid a memory leak. Pick-to: 5.15 Change-Id: I15c12b2f1b389638d5fe0a58599d9c410a033652 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/pdf/qpdfdocument.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp
index 5a8e0a1af..7e0d5e0cc 100644
--- a/src/pdf/qpdfdocument.cpp
+++ b/src/pdf/qpdfdocument.cpp
@@ -430,6 +430,8 @@ QRectF QPdfDocumentPrivate::getCharBox(FPDF_TEXTPAGE textPage, double pageHeight
QPdfDocumentPrivate::TextPosition QPdfDocumentPrivate::hitTest(int page, QPointF position)
{
const QPdfMutexLocker lock;
+
+ TextPosition result;
FPDF_PAGE pdfPage = FPDF_LoadPage(doc, page);
double pageHeight = FPDF_GetPageHeight(pdfPage);
FPDF_TEXTPAGE textPage = FPDFText_LoadPage(pdfPage);
@@ -446,10 +448,14 @@ QPdfDocumentPrivate::TextPosition QPdfDocumentPrivate::hitTest(int page, QPointF
++hitIndex;
}
qCDebug(qLcDoc) << "on page" << page << "@" << position << "got char position" << charPos << "index" << hitIndex;
- return { charPos, charBox.height(), hitIndex };
+ result = { charPos, charBox.height(), hitIndex };
}
}
- return {};
+
+ FPDFText_ClosePage(textPage);
+ FPDF_ClosePage(pdfPage);
+
+ return result;
}
/*!
@@ -795,6 +801,9 @@ QPdfSelection QPdfDocument::getSelection(int page, QPointF start, QPointF end)
CharacterHitTolerance, CharacterHitTolerance);
int endIndex = FPDFText_GetCharIndexAtPos(textPage, end.x(), pageHeight - end.y(),
CharacterHitTolerance, CharacterHitTolerance);
+
+ QPdfSelection result;
+
if (startIndex >= 0 && endIndex != startIndex) {
if (startIndex > endIndex)
qSwap(startIndex, endIndex);
@@ -821,11 +830,15 @@ QPdfSelection QPdfDocument::getSelection(int page, QPointF start, QPointF end)
bounds << QPolygonF(rect);
}
qCDebug(qLcDoc) << page << start << "->" << end << "found" << startIndex << "->" << endIndex << text;
- return QPdfSelection(text, bounds, hull, startIndex, endIndex);
+ result = QPdfSelection(text, bounds, hull, startIndex, endIndex);
+ } else {
+ qCDebug(qLcDoc) << page << start << "->" << end << "nothing found";
}
- qCDebug(qLcDoc) << page << start << "->" << end << "nothing found";
- return QPdfSelection();
+ FPDFText_ClosePage(textPage);
+ FPDF_ClosePage(pdfPage);
+
+ return result;
}
/*!
@@ -866,6 +879,10 @@ QPdfSelection QPdfDocument::getSelectionAtIndex(int page, int startIndex, int ma
hull = QRectF(d->getCharPosition(textPage, pageHeight, startIndex), QSizeF());
qCDebug(qLcDoc) << "on page" << page << "at index" << startIndex << "maxLength" << maxLength
<< "got" << text.length() << "chars," << rectCount << "rects within" << hull;
+
+ FPDFText_ClosePage(textPage);
+ FPDF_ClosePage(pdfPage);
+
return QPdfSelection(text, bounds, hull, startIndex, startIndex + text.length());
}
@@ -896,6 +913,10 @@ QPdfSelection QPdfDocument::getAllText(int page)
bounds << QPolygonF(rect);
}
qCDebug(qLcDoc) << "on page" << page << "got" << count << "chars," << rectCount << "rects within" << hull;
+
+ FPDFText_ClosePage(textPage);
+ FPDF_ClosePage(pdfPage);
+
return QPdfSelection(text, bounds, hull, 0, count);
}