Skip to content

Commit

Permalink
kvlist: Handle referenced condition on teardown
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Aug 27, 2024
1 parent f10ae81 commit b5c5015
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/cfl_kvlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

2 changes: 1 addition & 1 deletion tests/kvlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b5c5015

Please sign in to comment.