[pygobject/interface_override] interface: Fix leak when overriding GInterfaceInfo
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/interface_override] interface: Fix leak when overriding GInterfaceInfo
- Date: Tue, 29 Mar 2022 15:07:46 +0000 (UTC)
commit 4b96b3d7f450c569f2606df33f9206ae5ee52cf0
Author: Thibault Saunier <tsaunier igalia com>
Date: Tue Mar 29 18:38:00 2022 +0200
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.
gi/gimodule.c | 1 +
gi/pyginterface.c | 12 +++++++++---
2 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 7b23012e..766fd341 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -1751,6 +1751,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 *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]