Fixed memory leak in test

This commit is contained in:
John Jones 2016-12-14 12:24:44 -05:00
parent 033dd767b4
commit 5168bc87e0
3 changed files with 18 additions and 0 deletions

View file

@ -43,7 +43,11 @@ int ipfs_blocks_block_protobuf_encode(const struct Block* block, unsigned char*
size_t cid_size = ipfs_cid_protobuf_encode_size(block->cid); size_t cid_size = ipfs_cid_protobuf_encode_size(block->cid);
unsigned char cid[cid_size]; unsigned char cid[cid_size];
retVal = ipfs_cid_protobuf_encode(block->cid, cid, cid_size, &cid_size); retVal = ipfs_cid_protobuf_encode(block->cid, cid, cid_size, &cid_size);
if (retVal == 0)
return 0;
retVal = protobuf_encode_length_delimited(2, ipfs_block_message_fields[1], (char*)cid, cid_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used); retVal = protobuf_encode_length_delimited(2, ipfs_block_message_fields[1], (char*)cid, cid_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
if (retVal == 0)
return 0;
*bytes_written += bytes_used; *bytes_written += bytes_used;
return 1; return 1;
} }

View file

@ -178,17 +178,25 @@ int ipfs_node_protobuf_encode(struct Node* node, unsigned char* buffer, size_t m
*bytes_written = 0; *bytes_written = 0;
int retVal = 0; int retVal = 0;
retVal = protobuf_encode_length_delimited(1, ipfs_node_message_fields[0], (char*)node->data, node->data_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used); retVal = protobuf_encode_length_delimited(1, ipfs_node_message_fields[0], (char*)node->data, node->data_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
if (retVal == 0)
return 0;
*bytes_written += bytes_used; *bytes_written += bytes_used;
int sz = 0; int sz = 0;
if (node->encoded != NULL) if (node->encoded != NULL)
sz = strlen((char*)node->encoded); sz = strlen((char*)node->encoded);
retVal = protobuf_encode_length_delimited(2, ipfs_node_message_fields[1], (char*)node->encoded, sz, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used); retVal = protobuf_encode_length_delimited(2, ipfs_node_message_fields[1], (char*)node->encoded, sz, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
if (retVal == 0)
return 0;
*bytes_written += bytes_used; *bytes_written += bytes_used;
// cid // cid
size_t cid_size = ipfs_cid_protobuf_encode_size(node->cached); size_t cid_size = ipfs_cid_protobuf_encode_size(node->cached);
unsigned char cid[cid_size]; unsigned char cid[cid_size];
retVal = ipfs_cid_protobuf_encode(node->cached, cid, cid_size, &cid_size); retVal = ipfs_cid_protobuf_encode(node->cached, cid, cid_size, &cid_size);
if (retVal == 0)
return 0;
retVal = protobuf_encode_length_delimited(3, ipfs_node_message_fields[2], (char*)cid, cid_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used); retVal = protobuf_encode_length_delimited(3, ipfs_node_message_fields[2], (char*)cid, cid_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
if (retVal == 0)
return 0;
*bytes_written += bytes_used; *bytes_written += bytes_used;
// links // links
struct NodeLink* current = node->head_link; struct NodeLink* current = node->head_link;
@ -197,6 +205,8 @@ int ipfs_node_protobuf_encode(struct Node* node, unsigned char* buffer, size_t m
size_t link_buffer_size = 11 + ipfs_node_link_protobuf_encode_size(current); size_t link_buffer_size = 11 + ipfs_node_link_protobuf_encode_size(current);
unsigned char link_buffer[link_buffer_size]; unsigned char link_buffer[link_buffer_size];
retVal = ipfs_node_link_protobuf_encode(current, link_buffer, link_buffer_size, &link_buffer_size); retVal = ipfs_node_link_protobuf_encode(current, link_buffer, link_buffer_size, &link_buffer_size);
if (retVal == 0)
return 0;
protobuf_encode_length_delimited(4, ipfs_node_message_fields[3], (char*)link_buffer, link_buffer_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used); protobuf_encode_length_delimited(4, ipfs_node_message_fields[3], (char*)link_buffer, link_buffer_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
*bytes_written += bytes_used; *bytes_written += bytes_used;
current = current->next; current = current->next;

View file

@ -73,5 +73,9 @@ int test_import_small_file() {
} }
} }
ipfs_repo_fsrepo_free(fs_repo);
ipfs_node_free(write_node);
ipfs_node_free(read_node);
return 1; return 1;
} }