Skip to content

Commit

Permalink
Fix a memory leak in cbor_builder_byte_string_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
PJK committed Dec 27, 2022
1 parent d5ab430 commit 69b744f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cbor/internal/builder_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ void cbor_builder_byte_string_callback(void *context, cbor_data data,

if (ctx->stack->size > 0 && cbor_isa_bytestring(ctx->stack->top->item)) {
if (cbor_bytestring_is_indefinite(ctx->stack->top->item)) {
if (!cbor_bytestring_add_chunk(ctx->stack->top->item,
cbor_move(new_chunk))) {
if (!cbor_bytestring_add_chunk(ctx->stack->top->item, new_chunk)) {
ctx->creation_failed = true;
}
cbor_decref(&new_chunk);
} else {
cbor_decref(&new_chunk);
ctx->syntax_error = true;
Expand Down Expand Up @@ -280,6 +280,7 @@ void cbor_builder_string_callback(void *context, cbor_data data,
/* Careful here: order matters */
if (ctx->stack->size > 0 && cbor_isa_string(ctx->stack->top->item)) {
if (cbor_string_is_indefinite(ctx->stack->top->item)) {
// TODO: This can leak memory when adding the chunk fails
cbor_string_add_chunk(ctx->stack->top->item, cbor_move(res));
} else {
cbor_decref(&res);
Expand Down

0 comments on commit 69b744f

Please sign in to comment.