diff --git a/src/cfl_kvlist.c b/src/cfl_kvlist.c index 12c7711..66cd80e 100644 --- a/src/cfl_kvlist.c +++ b/src/cfl_kvlist.c @@ -508,11 +508,10 @@ void cfl_kvpair_destroy(struct cfl_kvpair *pair) cfl_sds_destroy(pair->key); } - if (pair->val != NULL) { + if (pair->val != NULL && !pair->val->referenced) { cfl_variant_destroy(pair->val); } free(pair); } } - diff --git a/tests/kvlist.c b/tests/kvlist.c index 87a5593..d3ce90a 100644 --- a/tests/kvlist.c +++ b/tests/kvlist.c @@ -1065,7 +1065,7 @@ static void test_basics() ret = cfl_kvlist_insert_string(list, "key1", "value1"); TEST_CHECK(ret == 0); - ret = cfl_kvlist_insert_bytes(list, "key2", "value2", 6, CFL_TRUE); + ret = cfl_kvlist_insert_bytes(list, "key2", "value2", 6, CFL_FALSE); TEST_CHECK(ret == 0); ret = cfl_kvlist_insert_reference(list, "key3", (void *) 0xdeadbeef);