Skip to content

Commit

Permalink
Fixed memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: leonard.kosta <[email protected]>
  • Loading branch information
kostaleonard committed Feb 16, 2024
1 parent 395499c commit 9b73bfc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/blockchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ return_code_t blockchain_deserialize(
total_read_size = next_spot_in_buffer + sizeof(uint64_t) - buffer;
if (total_read_size > buffer_size) {
return_code = FAILURE_BUFFER_TOO_SMALL;
blockchain_destroy(new_blockchain);
goto end;
}
uint64_t num_blocks = betoh64(*(uint64_t *)next_spot_in_buffer);
Expand Down
2 changes: 2 additions & 0 deletions tests/test_blockchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ void test_blockchain_deserialize_reconstructs_blockchain() {
assert_true(is_empty);
free(buffer);
blockchain_destroy(blockchain);
blockchain_destroy(deserialized_blockchain);
}

void test_blockchain_deserialize_fails_on_attempted_read_past_buffer() {
Expand Down Expand Up @@ -502,6 +503,7 @@ void test_blockchain_read_from_file_reconstructs_blockchain() {
&transaction->sender_signature,
&empty_signature,
sizeof(ssh_signature_t)));
blockchain_destroy(blockchain);
}

void test_blockchain_read_from_file_fails_on_invalid_input() {
Expand Down

0 comments on commit 9b73bfc

Please sign in to comment.