diff options
author | David Robillard <d@drobilla.net> | 2009-01-21 00:48:37 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-01-21 00:48:37 +0000 |
commit | c4e62bfdd15d9b0ab7ffed7629f5bbcb4e69bd33 (patch) | |
tree | fdafe2c585c6f53803facfd26ee849dacc1a99c1 | |
parent | c59b0892ace3ab0fb743335b36abbd72591d4a7b (diff) | |
download | lilv-c4e62bfdd15d9b0ab7ffed7629f5bbcb4e69bd33.tar.gz lilv-c4e62bfdd15d9b0ab7ffed7629f5bbcb4e69bd33.tar.bz2 lilv-c4e62bfdd15d9b0ab7ffed7629f5bbcb4e69bd33.zip |
Add slv2_plugin_classes_free to public API (fix ticket #324).
Fix memory leak in slv2_plugin_get_port_float_values.
Fix memory leak in slv2_plugin_get_supported_features.
Fix memory leak in slv2_port_has_property.
Fix several memory leaks in slv2_test program.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@1921 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | slv2/pluginclasses.h | 7 | ||||
-rw-r--r-- | slv2/port.h | 2 | ||||
-rw-r--r-- | slv2/value.h | 2 | ||||
-rw-r--r-- | src/plugin.c | 28 | ||||
-rw-r--r-- | src/pluginclass.c | 1 | ||||
-rw-r--r-- | src/pluginclasses.c | 1 | ||||
-rw-r--r-- | src/port.c | 9 | ||||
-rw-r--r-- | src/world.c | 2 | ||||
-rw-r--r-- | test/slv2_test.c | 43 | ||||
-rw-r--r-- | wscript | 3 |
10 files changed, 64 insertions, 34 deletions
diff --git a/slv2/pluginclasses.h b/slv2/pluginclasses.h index 5a13dbe..7ad3455 100644 --- a/slv2/pluginclasses.h +++ b/slv2/pluginclasses.h @@ -30,6 +30,13 @@ extern "C" { */ +/** Free an SLV2PluginClasses. + * Note that only certain plugin classes should be freed by the user + * (as specified by the documentation of the slv2 function which returned it). + */ +void slv2_plugin_classes_free(SLV2PluginClasses classes); + + /** Get the number of plugins in the collection. */ unsigned diff --git a/slv2/port.h b/slv2/port.h index 5dbe454..be6e03b 100644 --- a/slv2/port.h +++ b/slv2/port.h @@ -106,7 +106,7 @@ slv2_port_get_symbol(SLV2Plugin plugin, /** Get the name of a port. * * This is guaranteed to return the untranslated name (the doap:name in the - * data file without a language tag). Returned value must be free()'d by + * data file without a language tag). Returned value must be freed by * the caller. * * Time = Query diff --git a/slv2/value.h b/slv2/value.h index db447dd..f1af35f 100644 --- a/slv2/value.h +++ b/slv2/value.h @@ -89,7 +89,7 @@ slv2_value_equals(SLV2Value value, SLV2Value other); * 1.0 * 1 * - * Returned string is newly allocation and must be freed by caller. + * Returned string is newly allocated and must be freed by caller. */ char* slv2_value_get_turtle_token(SLV2Value value); diff --git a/src/plugin.c b/src/plugin.c index 6593029..870a32e 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -162,7 +162,6 @@ slv2_plugin_load(SLV2Plugin p) SLV2PluginClass plugin_class = slv2_plugin_classes_get_by_uri( p->world->plugin_classes, class); - librdf_free_node(class_node); @@ -539,17 +538,13 @@ void slv2_plugin_get_port_float_values(SLV2Plugin p, const char* qname, float* values) -{ - const unsigned char* query; - librdf_query* q; - librdf_query_results* results; - +{ slv2_plugin_load_if_necessary(p); for (int i = 0; i < raptor_sequence_size(p->ports); ++i) values[i] = NAN; - query = (const unsigned char*)slv2_strjoin( + unsigned char* query = (unsigned char*)slv2_strjoin( "PREFIX : <http://lv2plug.in/ns/lv2core#>\n" "SELECT DISTINCT ?index ?value WHERE {\n" "<> :port ?port .\n" @@ -557,10 +552,10 @@ slv2_plugin_get_port_float_values(SLV2Plugin p, "?port ", qname, " ?value .\n" "} ", NULL); - q = librdf_new_query(p->world->world, "sparql", + librdf_query* q = librdf_new_query(p->world->world, "sparql", NULL, query, slv2_value_as_librdf_uri(p->plugin_uri)); - results = librdf_query_execute(q, p->rdf); + librdf_query_results* results = librdf_query_execute(q, p->rdf); while (!librdf_query_results_finished(results)) { librdf_node* idx_node = librdf_query_results_get_binding_value(results, 0); @@ -578,6 +573,7 @@ slv2_plugin_get_port_float_values(SLV2Plugin p, librdf_free_query_results(results); librdf_free_query(q); + free(query); } @@ -666,7 +662,9 @@ slv2_plugin_get_latency_port_index(SLV2Plugin p) SLV2Value val = slv2_values_get_at(result, 0); assert(slv2_value_is_int(val)); - return slv2_value_as_int(val); + int ret = slv2_value_as_int(val); + slv2_values_free(result); + return ret; } @@ -691,11 +689,15 @@ slv2_plugin_get_supported_features(SLV2Plugin p) SLV2Values result = slv2_values_new(); unsigned n_optional = slv2_values_size(optional); + unsigned n_required = slv2_values_size(required); unsigned i = 0; for ( ; i < n_optional; ++i) - slv2_values_set_at(result, i, slv2_values_get_at(optional, i)); - for ( ; i < n_optional + slv2_values_size(required); ++i) - slv2_values_set_at(result, i, slv2_values_get_at(required, i - n_optional)); + slv2_values_set_at(result, i, raptor_sequence_pop(optional)); + for ( ; i < n_optional + n_required; ++i) + slv2_values_set_at(result, i, raptor_sequence_pop(required)); + + slv2_values_free(optional); + slv2_values_free(required); return result; } diff --git a/src/pluginclass.c b/src/pluginclass.c index 0ac9d05..6cc3bfe 100644 --- a/src/pluginclass.c +++ b/src/pluginclass.c @@ -39,7 +39,6 @@ slv2_plugin_class_new(SLV2World world, librdf_uri* parent_uri, librdf_uri* uri, } -/* private */ void slv2_plugin_class_free(SLV2PluginClass plugin_class) { diff --git a/src/pluginclasses.c b/src/pluginclasses.c index 3520359..1e7e69c 100644 --- a/src/pluginclasses.c +++ b/src/pluginclasses.c @@ -37,7 +37,6 @@ slv2_plugin_classes_new() void slv2_plugin_classes_free(SLV2PluginClasses list) { - //if (list != world->plugin_classes) if (list) raptor_free_sequence(list); } @@ -85,21 +85,16 @@ slv2_port_has_property(SLV2Plugin p, SLV2Value property) { assert(property); - - SLV2Values results = NULL; - char* query = slv2_strjoin( "SELECT DISTINCT ?port WHERE {\n" "<", slv2_value_as_uri(p->plugin_uri), "> lv2:port ?port ." "?port lv2:symbol \"", slv2_value_as_string(port->symbol), "\";\n", " lv2:portProperty <", slv2_value_as_uri(property), "> .\n}", NULL); - results = slv2_plugin_query_variable(p, query, 0); - + SLV2Values results = slv2_plugin_query_variable(p, query, 0); const bool ret = (slv2_values_size(results) > 0); - + slv2_values_free(results); free(query); - free(results); return ret; } diff --git a/src/world.c b/src/world.c index f93b732..cd85e8e 100644 --- a/src/world.c +++ b/src/world.c @@ -137,7 +137,7 @@ slv2_world_free(SLV2World world) raptor_free_sequence(world->plugins); world->plugins = NULL; - slv2_plugin_classes_free(world->plugin_classes); + raptor_free_sequence(world->plugin_classes); world->plugin_classes = NULL; librdf_free_parser(world->parser); diff --git a/test/slv2_test.c b/test/slv2_test.c index 4a65cb3..a298842 100644 --- a/test/slv2_test.c +++ b/test/slv2_test.c @@ -249,10 +249,18 @@ test_value() TEST_ASSERT(slv2_value_as_int(ival) == 42); TEST_ASSERT(fabs(slv2_value_as_float(fval) - 1.6180) < FLT_EPSILON); - TEST_ASSERT(!strcmp(slv2_value_get_turtle_token(uval), "<http://example.org>")); - TEST_ASSERT(!strcmp(slv2_value_get_turtle_token(sval), "Foo")); - TEST_ASSERT(!strcmp(slv2_value_get_turtle_token(ival), "42")); - TEST_ASSERT(!strncmp(slv2_value_get_turtle_token(fval), "1.6180", 6)); + char* tok = slv2_value_get_turtle_token(uval); + TEST_ASSERT(!strcmp(tok, "<http://example.org>")); + free(tok); + tok = slv2_value_get_turtle_token(sval); + TEST_ASSERT(!strcmp(tok, "Foo")); + free(tok); + tok = slv2_value_get_turtle_token(ival); + TEST_ASSERT(!strcmp(tok, "42")); + free(tok); + tok = slv2_value_get_turtle_token(fval); + TEST_ASSERT(!strncmp(tok, "1.6180", 6)); + free(tok); SLV2Value uval_e = slv2_value_new_uri(world, "http://example.org"); SLV2Value sval_e = slv2_value_new_string(world, "Foo"); @@ -282,6 +290,7 @@ test_value() SLV2Value ifval = slv2_value_new_float(world, 42.0); TEST_ASSERT(!slv2_value_equals(ival, ifval)); + slv2_value_free(ifval); SLV2Value nil = NULL; TEST_ASSERT(!slv2_value_equals(uval, nil)); @@ -435,8 +444,9 @@ test_discovery_variant(int load_all) TEST_ASSERT(explug2 == NULL); if (explug && expect_found) { - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_plugin_get_name(explug)), - "Test plugin")); + SLV2Value name = slv2_plugin_get_name(explug); + TEST_ASSERT(!strcmp(slv2_value_as_string(name), "Test plugin")); + slv2_value_free(name); } discovery_plugin_found = 0; @@ -555,6 +565,8 @@ test_classes() slv2_value_free(some_uri); TEST_ASSERT(slv2_plugin_classes_get_at(classes, (unsigned)INT_MAX + 1) == NULL); + + slv2_plugin_classes_free(children); cleanup_uris(); return 1; @@ -624,6 +636,9 @@ test_plugin() TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(data_uris, 0)), manifest_uri)); TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(data_uris, 1)), data_uri)); + free(manifest_uri); + free(data_uri); + float mins[1]; float maxs[1]; float defs[1]; @@ -664,12 +679,19 @@ test_plugin() TEST_ASSERT(slv2_plugin_has_feature(plug, event_feature)); TEST_ASSERT(!slv2_plugin_has_feature(plug, pretend_feature)); + slv2_value_free(rt_feature); + slv2_value_free(event_feature); + slv2_value_free(pretend_feature); + SLV2Values supported = slv2_plugin_get_supported_features(plug); SLV2Values required = slv2_plugin_get_required_features(plug); SLV2Values optional = slv2_plugin_get_optional_features(plug); TEST_ASSERT(slv2_values_size(supported) == 2); TEST_ASSERT(slv2_values_size(required) == 1); TEST_ASSERT(slv2_values_size(optional) == 1); + slv2_values_free(supported); + slv2_values_free(required); + slv2_values_free(optional); SLV2Value foo_p = slv2_value_new_uri(world, "http://example.org/foo"); SLV2Values foos = slv2_plugin_get_value(plug, foo_p); @@ -699,6 +721,7 @@ test_plugin() TEST_ASSERT(slv2_value_is_string(thing_name)); TEST_ASSERT(!strcmp(slv2_value_as_string(thing_name), "Something else")); + slv2_values_free(thing_names); slv2_value_free(thing_uri); slv2_value_free(name_p); slv2_value_free(control_class); @@ -773,7 +796,9 @@ test_port() TEST_ASSERT(slv2_values_size(slv2_port_get_properties(plug, p)) == 0); TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_port_get_symbol(plug, p)), "foo")); - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_port_get_name(plug, p)), "bar")); + SLV2Value name = slv2_port_get_name(plug, p); + TEST_ASSERT(!strcmp(slv2_value_as_string(name), "bar")); + slv2_value_free(name); SLV2ScalePoints points = slv2_port_get_scale_points(plug, p); TEST_ASSERT(slv2_scale_points_size(points) == 2); @@ -835,6 +860,7 @@ test_port() TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(names, 0)), "Event Input")); slv2_values_free(names); + slv2_value_free(name_p); TEST_ASSERT(slv2_port_get_value(plug, p, min) == NULL); @@ -950,8 +976,11 @@ test_ui() SLV2Value expected_uri = slv2_value_new_uri(world, ui_binary_uri_str); TEST_ASSERT(slv2_value_equals(expected_uri, ui_binary_uri)); + free(ui_binary_uri_str); + slv2_value_free(ui_class_uri); slv2_value_free(ui_uri); slv2_value_free(ui2_uri); + slv2_value_free(ui3_uri); slv2_value_free(noui_uri); slv2_value_free(expected_uri); slv2_uis_free(uis); @@ -26,8 +26,7 @@ SLV2_VERSION = '0.6.3' # 0.6.0 = 9,0,0 (SVN r1282) # 0.6.1 = 9,1,0 # 0.6.2 = 9,1,1 -# current svn = 9,1,2 -SLV2_LIB_VERSION = '9.1.2' +SLV2_LIB_VERSION = '9.1.3' # Variables for 'waf dist' APPNAME = 'slv2' |