fixed memory leak for file exporter
This commit is contained in:
parent
1d63cdb4a1
commit
87f0cbedbc
2 changed files with 20 additions and 5 deletions
|
@ -29,6 +29,9 @@ int ipfs_exporter_to_file(const unsigned char* hash, const char* file_name, cons
|
|||
return 0;
|
||||
}
|
||||
|
||||
// no longer need the cid
|
||||
ipfs_cid_free(cid);
|
||||
|
||||
// process blocks
|
||||
FILE* file = fopen(file_name, "wb");
|
||||
if (file == NULL) {
|
||||
|
@ -50,12 +53,13 @@ int ipfs_exporter_to_file(const unsigned char* hash, const char* file_name, cons
|
|||
return 0;
|
||||
}
|
||||
bytes_written = fwrite(link_node->data, 1, link_node->data_size, file);
|
||||
ipfs_node_free(link_node);
|
||||
if (bytes_written != link_node->data_size) {
|
||||
ipfs_node_free(link_node);
|
||||
fclose(file);
|
||||
ipfs_node_free(read_node);
|
||||
return 0;
|
||||
}
|
||||
ipfs_node_free(link_node);
|
||||
link = link->next;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
retVal = ipfs_repo_fsrepo_block_read(cid, &block, fs_repo);
|
||||
if (retVal == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// now convert the block into a node
|
||||
ipfs_node_protobuf_decode(block->data, block->data_length, node);
|
||||
// doesn't decode do this? No
|
||||
ipfs_node_set_cached(*node, cid);
|
||||
if (ipfs_node_protobuf_decode(block->data, block->data_length, node) == 0) {
|
||||
ipfs_blocks_block_free(block);
|
||||
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
|
||||
ipfs_blocks_block_free(block);
|
||||
|
||||
return retVal;
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue