From 03e318d5d80b0cfda96efc58e270693eeabe9a79 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 27 Apr 2011 21:23:25 +0000 Subject: Fix memory leaks. Don't modify model while reading it. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@3199 a436a847-0d15-0410-975c-d299462d15a1 --- src/value.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/value.c') diff --git a/src/value.c b/src/value.c index fd53197..e39e860 100644 --- a/src/value.c +++ b/src/value.c @@ -68,7 +68,8 @@ SLV2Value slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) { SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); - val->type = type; + val->world = world; + val->type = type; switch (type) { case SLV2_VALUE_URI: @@ -101,6 +102,7 @@ slv2_value_new_from_node(SLV2World world, SordNode node) case SORD_URI: type = SLV2_VALUE_URI; result = (SLV2Value)malloc(sizeof(struct _SLV2Value)); + result->world = world; result->type = SLV2_VALUE_URI; result->val.uri_val = slv2_node_copy(node); result->str_val = (char*)sord_node_get_string(result->val.uri_val); @@ -192,6 +194,7 @@ slv2_value_duplicate(SLV2Value val) return val; SLV2Value result = (SLV2Value)malloc(sizeof(struct _SLV2Value)); + result->world = val->world; result->type = val->type; if (val->type == SLV2_VALUE_URI) { @@ -210,7 +213,9 @@ void slv2_value_free(SLV2Value val) { if (val) { - if (val->type != SLV2_VALUE_URI) { + if (val->type == SLV2_VALUE_URI) { + slv2_node_free(val->world, val->val.uri_val); + } else { free(val->str_val); } free(val); -- cgit v1.2.1