fixed memory leak for file exporter

This commit is contained in:
John Jones 2016-12-15 13:06:12 -05:00
parent 1d63cdb4a1
commit 87f0cbedbc
2 changed files with 20 additions and 5 deletions

View file

@ -29,6 +29,9 @@ int ipfs_exporter_to_file(const unsigned char* hash, const char* file_name, cons
return 0; return 0;
} }
// no longer need the cid
ipfs_cid_free(cid);
// process blocks // process blocks
FILE* file = fopen(file_name, "wb"); FILE* file = fopen(file_name, "wb");
if (file == NULL) { if (file == NULL) {
@ -50,12 +53,13 @@ int ipfs_exporter_to_file(const unsigned char* hash, const char* file_name, cons
return 0; return 0;
} }
bytes_written = fwrite(link_node->data, 1, link_node->data_size, file); bytes_written = fwrite(link_node->data, 1, link_node->data_size, file);
ipfs_node_free(link_node);
if (bytes_written != link_node->data_size) { if (bytes_written != link_node->data_size) {
ipfs_node_free(link_node);
fclose(file); fclose(file);
ipfs_node_free(read_node); ipfs_node_free(read_node);
return 0; return 0;
} }
ipfs_node_free(link_node);
link = link->next; link = link->next;
} }

View file

@ -62,14 +62,25 @@ int ipfs_merkledag_get(const struct Cid* cid, struct Node** node, const struct F
// we have the record from the db. Go get the block from the blockstore // we have the record from the db. Go get the block from the blockstore
retVal = ipfs_repo_fsrepo_block_read(cid, &block, fs_repo); retVal = ipfs_repo_fsrepo_block_read(cid, &block, fs_repo);
if (retVal == 0) {
return 0;
}
// now convert the block into a node // now convert the block into a node
ipfs_node_protobuf_decode(block->data, block->data_length, node); if (ipfs_node_protobuf_decode(block->data, block->data_length, node) == 0) {
// doesn't decode do this? No ipfs_blocks_block_free(block);
ipfs_node_set_cached(*node, cid); return 0;
}
// set the cid on the node
if (ipfs_node_set_cached(*node, cid) == 0) {
ipfs_blocks_block_free(block);
ipfs_node_free(*node);
return 0;
}
// free resources // free resources
ipfs_blocks_block_free(block); ipfs_blocks_block_free(block);
return retVal; return 1;
} }