diff --git a/src/calibre/utils/podofo/doc.cpp b/src/calibre/utils/podofo/doc.cpp index adf8899e02..67f49b110b 100644 --- a/src/calibre/utils/podofo/doc.cpp +++ b/src/calibre/utils/podofo/doc.cpp @@ -18,6 +18,7 @@ static void PDFDoc_dealloc(PDFDoc* self) { if (self->doc != NULL) delete self->doc; + Py_CLEAR(self->load_buffer_ref); Py_TYPE(self)->tp_free((PyObject*)self); } @@ -45,6 +46,8 @@ PDFDoc_load(PDFDoc *self, PyObject *args) { try { self->doc->LoadFromBuffer(bufferview(buffer, size)); + self->load_buffer_ref = args; + Py_INCREF(args); } catch(const PdfError & err) { podofo_set_exception(err); return NULL; diff --git a/src/calibre/utils/podofo/global.h b/src/calibre/utils/podofo/global.h index 3743f7640b..87a56cb04b 100644 --- a/src/calibre/utils/podofo/global.h +++ b/src/calibre/utils/podofo/global.h @@ -26,6 +26,7 @@ typedef struct { PyObject_HEAD /* Type-specific fields go here. */ PdfMemDocument *doc; + PyObject *load_buffer_ref; } PDFDoc;