summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sord.c6
-rw-r--r--src/sord_test.c5
2 files changed, 8 insertions, 3 deletions
diff --git a/src/sord.c b/src/sord.c
index f375711..628a301 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -771,7 +771,7 @@ sord_new_node(SordNodeType type, const uint8_t* data, size_t n_bytes)
SordNode node = malloc(sizeof(struct _SordNode));
node->type = type;
node->n_bytes = n_bytes;
- node->refs = 0;
+ node->refs = 1;
node->datatype = 0;
node->lang = 0;
node->buf = (uint8_t*)g_strdup((const char*)data); // TODO: no-copy
@@ -845,7 +845,6 @@ sord_node_get_datatype(SordNode ref)
static void
sord_add_node(SordWorld world, SordNode node)
{
- node->refs = 0;
++world->n_nodes;
}
@@ -921,7 +920,8 @@ sord_node_free(SordWorld world, SordNode node)
return;
}
- if (node->refs == 0 || (--node->refs == 0)) {
+ assert(node->refs > 0);
+ if (--node->refs == 0) {
if (node->type == SORD_LITERAL) {
if (!g_hash_table_remove(world->literals, node)) {
fprintf(stderr, "Failed to remove literal from hash.\n");
diff --git a/src/sord_test.c b/src/sord_test.c
index 840b1e7..9d607fc 100644
--- a/src/sord_test.c
+++ b/src/sord_test.c
@@ -67,7 +67,11 @@ generate(SordWorld world, SordModel sord, size_t n_quads, size_t n_objects_per)
for (size_t j = 0; j < n_objects_per; ++j) {
SordQuad tup = { ids[0], ids[1], ids[2 + j] };
sord_add(sord, tup);
+ sord_node_free(world, ids[2 + j]);
}
+
+ sord_node_free(world, ids[0]);
+ sord_node_free(world, ids[1]);
}
// Add some literals
@@ -77,6 +81,7 @@ generate(SordWorld world, SordModel sord, size_t n_quads, size_t n_objects_per)
tup[2] = sord_new_literal(world, 0, (const uint8_t*)"hello", NULL);
tup[3] = 0;
sord_add(sord, tup);
+ sord_node_free(world, tup[2]);
tup[2] = sord_new_literal(world, 0, USTR("hi"), NULL);
sord_add(sord, tup);