Resolve LeakedDanglingUntriaged issues in PDFiumDocument.
Hold unique_ptr<> to chrome-specific subclasses of PDFium public API types so that their now non-trivial destructors will run and clear dangling counts when BRP is enabled. Bug: 1451541 Change-Id: I5a116eb1eb0edd457fead1f345f9b72b5d4f65a3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4590416 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org> Cr-Commit-Position: refs/heads/main@{#1153507}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
1ea7c37d14
commit
595d7c9e9e
pdf/pdfium
@ -12,9 +12,7 @@
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
namespace {
|
||||
|
||||
class FileAvail : public FX_FILEAVAIL {
|
||||
class PDFiumDocument::FileAvail : public FX_FILEAVAIL {
|
||||
public:
|
||||
explicit FileAvail(DocumentLoader* doc_loader) : doc_loader_(doc_loader) {
|
||||
DCHECK(doc_loader);
|
||||
@ -31,10 +29,10 @@ class FileAvail : public FX_FILEAVAIL {
|
||||
return file_avail->doc_loader_->IsDataAvailable(offset, size);
|
||||
}
|
||||
|
||||
raw_ptr<DocumentLoader, LeakedDanglingUntriaged> doc_loader_;
|
||||
raw_ptr<DocumentLoader> doc_loader_;
|
||||
};
|
||||
|
||||
class DownloadHints : public FX_DOWNLOADHINTS {
|
||||
class PDFiumDocument::DownloadHints : public FX_DOWNLOADHINTS {
|
||||
public:
|
||||
explicit DownloadHints(DocumentLoader* doc_loader) : doc_loader_(doc_loader) {
|
||||
DCHECK(doc_loader);
|
||||
@ -51,10 +49,10 @@ class DownloadHints : public FX_DOWNLOADHINTS {
|
||||
return download_hints->doc_loader_->RequestData(offset, size);
|
||||
}
|
||||
|
||||
raw_ptr<DocumentLoader, LeakedDanglingUntriaged> doc_loader_;
|
||||
raw_ptr<DocumentLoader> doc_loader_;
|
||||
};
|
||||
|
||||
class FileAccess : public FPDF_FILEACCESS {
|
||||
class PDFiumDocument::FileAccess : public FPDF_FILEACCESS {
|
||||
public:
|
||||
explicit FileAccess(DocumentLoader* doc_loader) : doc_loader_(doc_loader) {
|
||||
DCHECK(doc_loader);
|
||||
@ -73,11 +71,9 @@ class FileAccess : public FPDF_FILEACCESS {
|
||||
return file_access->doc_loader_->GetBlock(position, size, buffer);
|
||||
}
|
||||
|
||||
raw_ptr<DocumentLoader, LeakedDanglingUntriaged> doc_loader_;
|
||||
raw_ptr<DocumentLoader> doc_loader_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
PDFiumDocument::PDFiumDocument(DocumentLoader* doc_loader)
|
||||
: doc_loader_(doc_loader),
|
||||
file_access_(std::make_unique<FileAccess>(doc_loader)),
|
||||
@ -86,6 +82,18 @@ PDFiumDocument::PDFiumDocument(DocumentLoader* doc_loader)
|
||||
|
||||
PDFiumDocument::~PDFiumDocument() = default;
|
||||
|
||||
FPDF_FILEACCESS& PDFiumDocument::file_access() {
|
||||
return *file_access_;
|
||||
}
|
||||
|
||||
FX_FILEAVAIL& PDFiumDocument::file_availability() {
|
||||
return *file_availability_;
|
||||
}
|
||||
|
||||
FX_DOWNLOADHINTS& PDFiumDocument::download_hints() {
|
||||
return *download_hints_;
|
||||
}
|
||||
|
||||
void PDFiumDocument::CreateFPDFAvailability() {
|
||||
fpdf_availability_.reset(
|
||||
FPDFAvail_Create(file_availability_.get(), file_access_.get()));
|
||||
|
@ -19,14 +19,18 @@ class DocumentLoader;
|
||||
|
||||
class PDFiumDocument {
|
||||
public:
|
||||
class DownloadHints;
|
||||
class FileAccess;
|
||||
class FileAvail;
|
||||
|
||||
explicit PDFiumDocument(DocumentLoader* doc_loader);
|
||||
PDFiumDocument(const PDFiumDocument&) = delete;
|
||||
PDFiumDocument& operator=(const PDFiumDocument&) = delete;
|
||||
~PDFiumDocument();
|
||||
|
||||
FPDF_FILEACCESS& file_access() { return *file_access_; }
|
||||
FX_FILEAVAIL& file_availability() { return *file_availability_; }
|
||||
FX_DOWNLOADHINTS& download_hints() { return *download_hints_; }
|
||||
FPDF_FILEACCESS& file_access();
|
||||
FX_FILEAVAIL& file_availability();
|
||||
FX_DOWNLOADHINTS& download_hints();
|
||||
|
||||
FPDF_AVAIL fpdf_availability() const { return fpdf_availability_.get(); }
|
||||
FPDF_DOCUMENT doc() const { return doc_handle_.get(); }
|
||||
@ -46,13 +50,13 @@ class PDFiumDocument {
|
||||
const raw_ptr<DocumentLoader> doc_loader_;
|
||||
|
||||
// Interface structure to provide access to document stream.
|
||||
std::unique_ptr<FPDF_FILEACCESS> file_access_;
|
||||
std::unique_ptr<FileAccess> file_access_;
|
||||
|
||||
// Interface structure to check data availability in the document stream.
|
||||
std::unique_ptr<FX_FILEAVAIL> file_availability_;
|
||||
std::unique_ptr<FileAvail> file_availability_;
|
||||
|
||||
// Interface structure to request data chunks from the document stream.
|
||||
std::unique_ptr<FX_DOWNLOADHINTS> download_hints_;
|
||||
std::unique_ptr<DownloadHints> download_hints_;
|
||||
|
||||
// Pointer to the document availability interface.
|
||||
ScopedFPDFAvail fpdf_availability_;
|
||||
|
Reference in New Issue
Block a user