Fixing memory leaks
This commit is contained in:
parent
6754ba77b3
commit
c58134db1c
7 changed files with 25 additions and 28 deletions
|
@ -103,7 +103,8 @@ int ipfs_bitswap_network_handle_message(const struct IpfsNode* node, const struc
|
|||
if (message->payload != NULL) {
|
||||
for(int i = 0; i < message->payload->total; i++) {
|
||||
struct Block* blk = (struct Block*)libp2p_utils_vector_get(message->payload, i);
|
||||
node->exchange->HasBlock(node->exchange, blk);
|
||||
// we need a copy of the block so it survives the destruction of the message
|
||||
node->exchange->HasBlock(node->exchange, ipfs_block_copy(blk));
|
||||
}
|
||||
}
|
||||
// wantlist - what they want
|
||||
|
@ -119,19 +120,8 @@ int ipfs_bitswap_network_handle_message(const struct IpfsNode* node, const struc
|
|||
ipfs_bitswap_message_free(message);
|
||||
return 0;
|
||||
}
|
||||
// find the queue
|
||||
struct PeerRequestEntry* queueEntry = ipfs_bitswap_peer_request_queue_find_entry(bitswapContext->peerRequestQueue, peer);
|
||||
if (queueEntry == NULL) {
|
||||
// add the queue
|
||||
struct PeerRequest* peerRequest =ipfs_bitswap_peer_request_new();
|
||||
peerRequest->peer = peer;
|
||||
ipfs_bitswap_peer_request_queue_add(bitswapContext->peerRequestQueue, peerRequest);
|
||||
queueEntry = ipfs_bitswap_peer_request_queue_find_entry(bitswapContext->peerRequestQueue, peer);
|
||||
if (queueEntry == NULL) {
|
||||
ipfs_bitswap_message_free(message);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// find the queue (adds it if it is not there)
|
||||
struct PeerRequest* peerRequest = ipfs_peer_request_queue_find_peer(bitswapContext->peerRequestQueue, peer);
|
||||
for(int i = 0; i < message->wantlist->entries->total; i++) {
|
||||
struct WantlistEntry* entry = (struct WantlistEntry*) libp2p_utils_vector_get(message->wantlist->entries, i);
|
||||
// turn the "block" back into a cid
|
||||
|
@ -142,7 +132,7 @@ int ipfs_bitswap_network_handle_message(const struct IpfsNode* node, const struc
|
|||
ipfs_bitswap_message_free(message);
|
||||
return 0;
|
||||
}
|
||||
ipfs_bitswap_network_adjust_cid_queue(queueEntry->current->cids_they_want, cid, entry->cancel);
|
||||
ipfs_bitswap_network_adjust_cid_queue(peerRequest->cids_they_want, cid, entry->cancel);
|
||||
}
|
||||
}
|
||||
ipfs_bitswap_message_free(message);
|
||||
|
|
|
@ -176,9 +176,9 @@ int ipfs_bitswap_peer_request_queue_remove(struct PeerRequestQueue* queue, struc
|
|||
}
|
||||
|
||||
/**
|
||||
* Finds a PeerRequestEntry that contains the specified PeerRequest
|
||||
* Finds a PeerRequestEntry that contains the specified Peer
|
||||
* @param queue the queue to look through
|
||||
* @param request what we're looking for
|
||||
* @param peer what we're looking for
|
||||
* @returns the PeerRequestEntry or NULL if not found
|
||||
*/
|
||||
struct PeerRequestEntry* ipfs_bitswap_peer_request_queue_find_entry(struct PeerRequestQueue* queue, struct Libp2pPeer* peer) {
|
||||
|
|
|
@ -262,7 +262,7 @@ int ipfs_bitswap_wantlist_get_block_remote(struct BitswapContext* context, struc
|
|||
// add this to their queue
|
||||
struct PeerRequest* queueEntry = ipfs_peer_request_queue_find_peer(context->peerRequestQueue, current);
|
||||
struct CidEntry* entry = ipfs_bitswap_peer_request_cid_entry_new();
|
||||
entry->cid = cid;
|
||||
entry->cid = ipfs_cid_copy(cid);
|
||||
libp2p_utils_vector_add(queueEntry->cids_we_want, entry);
|
||||
// process this queue via bitswap protocol
|
||||
ipfs_bitswap_peer_request_process_entry(context, queueEntry);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue