aboutsummaryrefslogtreecommitdiffstats
path: root/main/gobject-introspection/0007-giconstantinfo-Add-API-to-fix-memory-leak.patch
blob: 09f0398a9f6bda7285a4a82da6999269d49a415c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
From 8e970f46b8525396009d4d833a1f1cdacd3df6a1 Mon Sep 17 00:00:00 2001
From: "Jasper St. Pierre" <jstpierre@mecheye.net>
Date: Wed, 5 Oct 2011 16:31:43 -0400
Subject: [PATCH 7/8] giconstantinfo: Add API to fix memory leak

https://bugzilla.gnome.org/show_bug.cgi?id=654069
---
 girepository/giconstantinfo.c |   30 ++++++++++++++++++++++++++++++
 girepository/giconstantinfo.h |    2 ++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/girepository/giconstantinfo.c b/girepository/giconstantinfo.c
index c082303..2c3cc29 100644
--- a/girepository/giconstantinfo.c
+++ b/girepository/giconstantinfo.c
@@ -69,6 +69,35 @@ g_constant_info_get_type (GIConstantInfo *info)
         memcpy((dest_addr), (src_addr), sizeof(type))
 
 /**
+ * g_constant_info_free_value: (skip)
+ * @info: a #GIConstantInfo
+ * @value: the argument
+ *
+ * Free the value returned from g_constant_info_get_value().
+ *
+ * Since: 1.30.1
+ */
+void
+g_constant_info_free_value (GIConstantInfo *info,
+                            GIArgument     *value)
+{
+  GIRealInfo *rinfo = (GIRealInfo *)info;
+  ConstantBlob *blob;
+
+  g_return_if_fail (info != NULL);
+  g_return_if_fail (GI_IS_CONSTANT_INFO (info));
+
+  blob = (ConstantBlob *)&rinfo->typelib->data[rinfo->offset];
+
+  /* FIXME non-basic types ? */
+  if (blob->type.flags.reserved == 0 && blob->type.flags.reserved2 == 0)
+    {
+      if (blob->type.flags.pointer)
+        g_free (value->v_pointer);
+    }
+}
+
+/**
  * g_constant_info_get_value: (skip)
  * @info: a #GIConstantInfo
  * @value: (out): an argument
@@ -76,6 +105,7 @@ g_constant_info_get_type (GIConstantInfo *info)
  * Obtain the value associated with the #GIConstantInfo and store it in the
  * @value parameter. @argument needs to be allocated before passing it in.
  * The size of the constant value stored in @argument will be returned.
+ * Free the value with g_constant_info_free_value().
  *
  * Returns: size of the constant
  */
diff --git a/girepository/giconstantinfo.h b/girepository/giconstantinfo.h
index a2679bd..2e7d697 100644
--- a/girepository/giconstantinfo.h
+++ b/girepository/giconstantinfo.h
@@ -34,6 +34,8 @@ G_BEGIN_DECLS
     (g_base_info_get_type((GIBaseInfo*)info) ==  GI_INFO_TYPE_CONSTANT)
 
 GITypeInfo * g_constant_info_get_type (GIConstantInfo *info);
+void         g_constant_info_free_value(GIConstantInfo *info,
+                                        GIArgument      *value);
 gint         g_constant_info_get_value(GIConstantInfo *info,
 				       GIArgument      *value);
 G_END_DECLS
-- 
1.7.7