[gupnp-vala] gupnp: Use pointers for Value
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp-vala] gupnp: Use pointers for Value
- Date: Mon, 13 Feb 2012 06:04:51 +0000 (UTC)
commit ed610fd393950d32ee46a937c72c76b0fcb4da80
Author: Jens Georg <mail jensge org>
Date: Wed Feb 8 22:36:32 2012 +0200
gupnp: Use pointers for Value
gupnp and vala disagree about the memory management of the values;
GUPnP allocates them with g_slice_alloc while vala tries to free them
with g_free, leading to memory corruption.
There's no chance but to take the Values generated by GUPnP out of the
automatic memory management and let the user deal with it.
This patch also adds helper functions to free the data structures.
https://bugzilla.gnome.org/show_bug.cgi?id=669702
gupnp-1.0/gupnp-1.0-custom.vala | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/gupnp-1.0/gupnp-1.0-custom.vala b/gupnp-1.0/gupnp-1.0-custom.vala
index 9b687f1..1d9eb91 100644
--- a/gupnp-1.0/gupnp-1.0-custom.vala
+++ b/gupnp-1.0/gupnp-1.0-custom.vala
@@ -20,18 +20,31 @@
*/
namespace GUPnP {
-
+ public static void value_list_free (GLib.List<weak GLib.Value*> list) {
+ foreach (var v in list) {
+ v->unset ();
+ GLib.Slice.free (sizeof (GLib.Value), v);
+ }
+ }
+
+ public static void value_hash_free (GLib.HashTable<string, weak GLib.Value*> hash) {
+ hash.for_each ((k, v) => {
+ v->unset ();
+ GLib.Slice.free (sizeof (GLib.Value), v);
+ });
+ }
+
public class ServiceProxy {
[CCode (has_construct_function = false)]
public ServiceProxy ();
public virtual signal void subscription_lost (GLib.Error reason);
- public bool end_action_hash (GUPnP.ServiceProxyAction action, [CCode (pos=-0.9)] GLib.HashTable<string, GLib.Value?> hash) throws GLib.Error;
- public bool end_action_list (GUPnP.ServiceProxyAction action, [CCode (pos=-0.9)] GLib.List<string> out_names, [CCode (pos=-0.8)] GLib.List<GLib.Type?> out_types, [CCode (pos=-0.7)] out GLib.List<GLib.Value?> out_values) throws GLib.Error;
+ public bool end_action_hash (GUPnP.ServiceProxyAction action, [CCode (pos=-0.9)] GLib.HashTable<string, weak GLib.Value*> hash) throws GLib.Error;
+ public bool end_action_list (GUPnP.ServiceProxyAction action, [CCode (pos=-0.9)] GLib.List<string> out_names, [CCode (pos=-0.8)] GLib.List<GLib.Type?> out_types, [CCode (pos=-0.7)] out GLib.List<weak GLib.Value*> out_values) throws GLib.Error;
- public bool send_action_hash (string action, [CCode (pos=-0.9)] GLib.HashTable<string, GLib.Value?> in_hash, [CCode (pos=-0.8)] GLib.HashTable<string, GLib.Value?> out_hash) throws GLib.Error;
- public bool send_action_list (string action, [CCode (pos=-0.9)]GLib.List<string> in_names, [CCode (pos=-0.8)]GLib.List<GLib.Value?> in_values, [CCode (pos=-0.7)] GLib.List<string> out_names, [CCode (pos=-0.6)]GLib.List<GLib.Type?> out_types, [CCode (pos=-0.5)] out GLib.List<GLib.Value?> out_values) throws GLib.Error;
+ public bool send_action_hash (string action, [CCode (pos=-0.9)] GLib.HashTable<string, GLib.Value?> in_hash, [CCode (pos=-0.8)] GLib.HashTable<string, weak GLib.Value*> out_hash) throws GLib.Error;
+ public bool send_action_list (string action, [CCode (pos=-0.9)] GLib.List<string> in_names, [CCode (pos=-0.8)] GLib.List<weak GLib.Value?> in_values, [CCode (pos=-0.7)] GLib.List<string> out_names, [CCode (pos=-0.6)] GLib.List<GLib.Type?> out_types, [CCode (pos=-0.5)] out GLib.List<weak GLib.Value*> out_values) throws GLib.Error;
}
public class Service {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]