glib/poppler-attachment.cc | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
New commits: commit 6ced3253fa3356e50d6c1dfa8961561eabefb9e8 Author: Christian Persch <[email protected]> Date: Tue Oct 23 23:42:47 2018 +0200 glib: Fix missing destructor call PopplerAttachmentPrivate has a Object member which was never destructed, only set to an empty Object() on dispose. While there is no memory leak (currently!), this is still not correct. Fix this by making PopplerAttachmentPrivate a C++ class, constructed in place of the gobject instance private in init(), and call the destructor explicitly in finalize(). diff --git a/glib/poppler-attachment.cc b/glib/poppler-attachment.cc index 11ba5bb5..87baef22 100644 --- a/glib/poppler-attachment.cc +++ b/glib/poppler-attachment.cc @@ -23,6 +23,8 @@ #include "poppler.h" #include "poppler-private.h" +#include <new> + /** * SECTION:poppler-attachment * @short_description: Attachments @@ -32,15 +34,13 @@ /* FIXME: We need to add gettext support sometime */ #define _(x) (x) -typedef struct _PopplerAttachmentPrivate PopplerAttachmentPrivate; -struct _PopplerAttachmentPrivate +struct PopplerAttachmentPrivate { - Object obj_stream; + Object obj_stream{}; }; #define POPPLER_ATTACHMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), POPPLER_TYPE_ATTACHMENT, PopplerAttachmentPrivate)) -static void poppler_attachment_dispose (GObject *obj); static void poppler_attachment_finalize (GObject *obj); G_DEFINE_TYPE (PopplerAttachment, poppler_attachment, G_TYPE_OBJECT) @@ -48,28 +48,20 @@ G_DEFINE_TYPE (PopplerAttachment, poppler_attachment, G_TYPE_OBJECT) static void poppler_attachment_init (PopplerAttachment *attachment) { + void *place; + + place = g_type_instance_get_private ((GTypeInstance*)attachment, POPPLER_TYPE_ATTACHMENT); + new (place) PopplerAttachmentPrivate(); } static void poppler_attachment_class_init (PopplerAttachmentClass *klass) { - G_OBJECT_CLASS (klass)->dispose = poppler_attachment_dispose; G_OBJECT_CLASS (klass)->finalize = poppler_attachment_finalize; g_type_class_add_private (klass, sizeof (PopplerAttachmentPrivate)); } static void -poppler_attachment_dispose (GObject *obj) -{ - PopplerAttachmentPrivate *priv; - - priv = POPPLER_ATTACHMENT_GET_PRIVATE (obj); - priv->obj_stream = Object(); - - G_OBJECT_CLASS (poppler_attachment_parent_class)->dispose (obj); -} - -static void poppler_attachment_finalize (GObject *obj) { PopplerAttachment *attachment; @@ -87,7 +79,9 @@ poppler_attachment_finalize (GObject *obj) if (attachment->checksum) g_string_free (attachment->checksum, TRUE); attachment->checksum = nullptr; - + + POPPLER_ATTACHMENT_GET_PRIVATE (obj)->~PopplerAttachmentPrivate (); + G_OBJECT_CLASS (poppler_attachment_parent_class)->finalize (obj); } _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
