Skip to content

Commit

Permalink
Array & map deallocation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
PJK committed Apr 26, 2015
1 parent dac7570 commit 4e32c96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ void cbor_decref(cbor_item_t ** item)
cbor_item_t ** handle = cbor_array_handle(*item);
for (size_t i = 0; i < cbor_array_size(*item); i++)
cbor_decref(&handle[i]);
/* Fallthrough */
_CBOR_FREE((*item)->data);
break;
}
case CBOR_TYPE_MAP:
{
struct cbor_pair * handle = cbor_map_handle(*item);
for (size_t i = 0; i < cbor_map_size(*item); i++, handle++) {
cbor_decref(&handle->key);
cbor_decref(&handle->value);
}
_CBOR_FREE((*item)->data);
break;
};
case CBOR_TYPE_TAG:
{
cbor_decref(&(*item)->metadata.tag_metadata.tagged_item);
Expand Down
1 change: 1 addition & 0 deletions test/type_4_encoders_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static void test_indef_array_encoding(void **state) {
cbor_array_push(array, two);
assert_int_equal(3, cbor_serialize_array(array, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){ 0x9F, 0x01, 0x02 }), 3);
cbor_decref(&array);
}

int main(void) {
Expand Down

0 comments on commit 4e32c96

Please sign in to comment.