Fixed mem leak and more testing

This commit is contained in:
John Jones 2017-07-31 13:32:09 -05:00
parent e4f1c9b39c
commit 3a68619016
4 changed files with 23 additions and 3 deletions

View file

@ -17,8 +17,17 @@
struct PeerRequest* ipfs_bitswap_peer_request_new() { struct PeerRequest* ipfs_bitswap_peer_request_new() {
struct PeerRequest* request = (struct PeerRequest*) malloc(sizeof(struct PeerRequest)); struct PeerRequest* request = (struct PeerRequest*) malloc(sizeof(struct PeerRequest));
if (request != NULL) { if (request != NULL) {
request->cids = NULL; request->cids = libp2p_utils_vector_new(1);
request->blocks = NULL; if (request->cids == NULL) {
free(request);
return NULL;
}
request->blocks = libp2p_utils_vector_new(1);
if (request->blocks == NULL) {
libp2p_utils_vector_free(request->cids);
free(request);
return NULL;
}
request->peer = NULL; request->peer = NULL;
} }
return request; return request;
@ -240,6 +249,7 @@ struct PeerRequest* ipfs_peer_request_queue_find_peer(struct PeerRequestQueue* q
} }
entry = ipfs_bitswap_peer_request_entry_new(); entry = ipfs_bitswap_peer_request_entry_new();
entry->current = ipfs_bitswap_peer_request_new();
entry->current->peer = peer; entry->current->peer = peer;
entry->prior = queue->last; entry->prior = queue->last;
queue->last = entry; queue->last = entry;

View file

@ -24,6 +24,12 @@ int repo_config_identity_build_peer_id(struct Identity* identity) {
public_key.data = (unsigned char*)identity->private_key.public_key_der; public_key.data = (unsigned char*)identity->private_key.public_key_der;
public_key.data_size = identity->private_key.public_key_length; public_key.data_size = identity->private_key.public_key_length;
public_key.type = KEYTYPE_RSA; public_key.type = KEYTYPE_RSA;
if (identity->peer == NULL)
identity->peer = libp2p_peer_new();
if (identity->peer->id != NULL) {
free(identity->peer->id);
identity->peer->id = NULL;
}
if (!libp2p_crypto_public_key_to_peer_id(&public_key, &identity->peer->id)) if (!libp2p_crypto_public_key_to_peer_id(&public_key, &identity->peer->id))
return 0; return 0;
identity->peer->id_size = strlen(identity->peer->id); identity->peer->id_size = strlen(identity->peer->id);

View file

@ -517,6 +517,8 @@ ipfs_routing* ipfs_routing_new_online (struct IpfsNode* local_node, struct RsaPr
onlineRouting->local_node->mode = MODE_ONLINE; onlineRouting->local_node->mode = MODE_ONLINE;
onlineRouting->Bootstrap(onlineRouting);
return onlineRouting; return onlineRouting;
} }

View file

@ -306,8 +306,10 @@ int test_bitswap_retrieve_file_known_remote() {
ipfs_node2->routing->Bootstrap(ipfs_node2->routing); ipfs_node2->routing->Bootstrap(ipfs_node2->routing);
if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hello_world_hash, strlen(hello_world_hash), &cid))
goto exit;
// this does the heavy lifting... // this does the heavy lifting...
cid = ipfs_cid_new(0, (unsigned char*)hello_world_hash, strlen(hello_world_hash), CID_PROTOBUF);
if (!ipfs_node2->exchange->GetBlock(ipfs_node2->exchange, cid, &result)) { if (!ipfs_node2->exchange->GetBlock(ipfs_node2->exchange, cid, &result)) {
libp2p_logger_error("test_bitswap", "GetBlock returned false\n"); libp2p_logger_error("test_bitswap", "GetBlock returned false\n");
goto exit; goto exit;