diff options
author | Thibault Saunier <tsaunier@igalia.com> | 2022-03-29 18:38:00 +0200 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2022-04-24 11:48:40 +0200 |
commit | 178bd23b1185fa83c14db1be289533c0c4401b07 (patch) | |
tree | 35a71d05d3253de07a18a304e465670f6e0ecb40 | |
parent | 5d68c257e701ecb57713630609158d5711b31bf7 (diff) | |
download | pygobject-178bd23b1185fa83c14db1be289533c0c4401b07.tar.gz |
interface: Fix leak when overriding GInterfaceInfo
When the interface is being registered by PyGObject and again through
an override, the first one is being leaks, free it at this point.
We need to copy the GInterfaceInfo to set on the GType QData as we
do not own it.
-rw-r--r-- | gi/gimodule.c | 1 | ||||
-rw-r--r-- | gi/pyginterface.c | 12 | ||||
-rw-r--r-- | meson.build | 4 | ||||
-rwxr-xr-x | setup.py | 5 |
4 files changed, 19 insertions, 3 deletions
diff --git a/gi/gimodule.c b/gi/gimodule.c index 60f1a961..230882f0 100644 --- a/gi/gimodule.c +++ b/gi/gimodule.c @@ -1742,6 +1742,7 @@ _wrap_pyg_register_interface_info (PyObject *self, PyObject *args) info->interface_init = (GInterfaceInitFunc) initialize_interface; pyg_register_interface_info (g_type, info); + g_free (info); Py_RETURN_NONE; } diff --git a/gi/pyginterface.c b/gi/pyginterface.c index 34db8fac..288fbb25 100644 --- a/gi/pyginterface.c +++ b/gi/pyginterface.c @@ -85,15 +85,21 @@ pyg_register_interface(PyObject *dict, const gchar *class_name, } g_type_set_qdata(gtype, pyginterface_type_key, type); - + PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type); - + } void pyg_register_interface_info(GType gtype, const GInterfaceInfo *info) { - g_type_set_qdata(gtype, pyginterface_info_key, (gpointer) info); + GInterfaceInfo *prev_info = pyg_lookup_interface_info (gtype); + + if (prev_info) { + g_free (prev_info); + } + + g_type_set_qdata(gtype, pyginterface_info_key, g_memdup2 (info, sizeof(GInterfaceInfo))); } const GInterfaceInfo * diff --git a/meson.build b/meson.build index ae1f72ff..2698e571 100644 --- a/meson.build +++ b/meson.build @@ -136,6 +136,10 @@ cdata.set('PYGOBJECT_MAJOR_VERSION', pygobject_version_major) cdata.set('PYGOBJECT_MINOR_VERSION', pygobject_version_minor) cdata.set('PYGOBJECT_MICRO_VERSION', pygobject_version_micro) +if gio_dep.version().version_compare('< 2.67.4') + cdata.set('g_memdup2(ptr,sz)', '(G_LIKELY(((guint64)(sz)) < G_MAXUINT)) ? g_memdup(ptr,sz) : (g_abort(),NULL)') +endif + configure_file(output : 'config.h', configuration : cdata) pkgconf = configuration_data() @@ -1018,6 +1018,11 @@ class build_ext(du_build_ext): /* Configuration header created by setup.py - do not edit */ #ifndef _CONFIG_H #define _CONFIG_H 1 +#include <glib.h> + +#if !GLIB_CHECK_VERSION(2, 67, 4) +#define g_memdup2(ptr,sz) (G_LIKELY(((guint64)(sz)) < G_MAXUINT)) ? g_memdup(ptr,sz) : (g_abort(),NULL) +#endif #define PYGOBJECT_MAJOR_VERSION %(PYGOBJECT_MAJOR_VERSION)s #define PYGOBJECT_MINOR_VERSION %(PYGOBJECT_MINOR_VERSION)s |