[poppler] glib/poppler-document.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Mar 28 11:57:39 UTC 2022


 glib/poppler-document.cc |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

New commits:
commit 6299164caa78bc3b90154f9580a17e1aa112b5cd
Author: Christian Persch <chpe at src.gnome.org>
Date:   Sun Mar 27 23:10:13 2022 +0200

    glib: Fix mem leak in poppler_document_new_from_fd
    
    Someone needs to own the GooFile that's referenced by FileStream. Add a
    simple OwningFileStream class that does that.
    
    Fixes: https://gitlab.freedesktop.org/poppler/poppler/-/issues/1227

diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 84584314..a74312ff 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -285,6 +285,19 @@ public:
 
 BytesStream::~BytesStream() = default;
 
+class OwningFileStream final : public FileStream
+{
+public:
+    OwningFileStream(std::unique_ptr<GooFile> fileA, Object &&dictA) : FileStream(fileA.get(), 0, false, fileA->size(), std::move(dictA)), file(std::move(fileA)) { }
+
+    ~OwningFileStream() override;
+
+private:
+    std::unique_ptr<GooFile> file;
+};
+
+OwningFileStream::~OwningFileStream() = default;
+
 /**
  * poppler_document_new_from_bytes:
  * @bytes: a #GBytes
@@ -499,9 +512,7 @@ PopplerDocument *poppler_document_new_from_fd(int fd, const char *password, GErr
         CachedFile *cachedFile = new CachedFile(new FILECacheLoader(file), nullptr);
         stream = new CachedFileStream(cachedFile, 0, false, cachedFile->getLength(), Object(objNull));
     } else {
-        std::unique_ptr<GooFile> file = GooFile::open(fd);
-        // FIXME file is getting leak here
-        stream = new FileStream(file.release(), 0, false, file->size(), Object(objNull));
+        stream = new OwningFileStream(GooFile::open(fd), Object(objNull));
     }
 
     const std::optional<GooString> password_g = poppler_password_to_latin1(password);


More information about the poppler mailing list