From 3a68619016f8ddc869a1820e8a4d80fbfce13956 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 31 Jul 2017 13:32:09 -0500 Subject: [PATCH] Fixed mem leak and more testing --- exchange/bitswap/peer_request_queue.c | 14 ++++++++++++-- repo/config/identity.c | 6 ++++++ routing/online.c | 2 ++ test/exchange/test_bitswap.h | 4 +++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/exchange/bitswap/peer_request_queue.c b/exchange/bitswap/peer_request_queue.c index 8400ead..73a388d 100644 --- a/exchange/bitswap/peer_request_queue.c +++ b/exchange/bitswap/peer_request_queue.c @@ -17,8 +17,17 @@ struct PeerRequest* ipfs_bitswap_peer_request_new() { struct PeerRequest* request = (struct PeerRequest*) malloc(sizeof(struct PeerRequest)); if (request != NULL) { - request->cids = NULL; - request->blocks = NULL; + request->cids = libp2p_utils_vector_new(1); + 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; } 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->current = ipfs_bitswap_peer_request_new(); entry->current->peer = peer; entry->prior = queue->last; queue->last = entry; diff --git a/repo/config/identity.c b/repo/config/identity.c index 1db6e6f..5afd8db 100644 --- a/repo/config/identity.c +++ b/repo/config/identity.c @@ -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_size = identity->private_key.public_key_length; 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)) return 0; identity->peer->id_size = strlen(identity->peer->id); diff --git a/routing/online.c b/routing/online.c index 2fa3075..4791c81 100644 --- a/routing/online.c +++ b/routing/online.c @@ -517,6 +517,8 @@ ipfs_routing* ipfs_routing_new_online (struct IpfsNode* local_node, struct RsaPr onlineRouting->local_node->mode = MODE_ONLINE; + onlineRouting->Bootstrap(onlineRouting); + return onlineRouting; } diff --git a/test/exchange/test_bitswap.h b/test/exchange/test_bitswap.h index 45d7483..cc2aaaf 100644 --- a/test/exchange/test_bitswap.h +++ b/test/exchange/test_bitswap.h @@ -306,8 +306,10 @@ int test_bitswap_retrieve_file_known_remote() { 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... - 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)) { libp2p_logger_error("test_bitswap", "GetBlock returned false\n"); goto exit;