summaryrefslogtreecommitdiff
path: root/glib/poppler-attachment.cc
diff options
context:
space:
mode:
authorChristian Persch <chpe@src.gnome.org>2018-10-23 23:42:47 +0200
committerAlbert Astals Cid <tsdgeos@yahoo.es>2018-11-03 11:22:58 +0000
commit6ced3253fa3356e50d6c1dfa8961561eabefb9e8 (patch)
tree286c1a3b4d71d6f2702f4db5cc51df31bf4744cc /glib/poppler-attachment.cc
parent08572e1bdca03baed694dd9828bb2b878865e669 (diff)
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().
Diffstat (limited to 'glib/poppler-attachment.cc')
-rw-r--r--glib/poppler-attachment.cc28
1 files changed, 11 insertions, 17 deletions
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);
}