Return a copy of the block from the exchange, not the block itself

Returning the block itself will cause problems when a client deallocates
the block.
This commit is contained in:
John Jones 2017-10-09 10:01:29 -05:00
parent f69ab92469
commit 98b1e0fef4
3 changed files with 9 additions and 4 deletions

View file

@ -183,7 +183,7 @@ int ipfs_bitswap_get_block(struct Exchange* exchange, struct Cid* cid, struct Bl
// loop waiting for it to fill
while(1) {
if (want_entry->block != NULL) {
*block = want_entry->block;
*block = ipfs_block_copy(want_entry->block);
// error or not, we no longer need the block (decrement reference count)
ipfs_bitswap_want_manager_remove(bitswapContext, cid);
if (*block == NULL) {

View file

@ -20,7 +20,7 @@
int ipfs_bitswap_network_send_message(const struct BitswapContext* context, struct Libp2pPeer* peer, const struct BitswapMessage* message) {
libp2p_logger_debug("bitswap_network", "Sending bitswap message to %s.\n", libp2p_peer_id_to_string(peer));
// get a connection to the peer
if (peer->connection_type != CONNECTION_TYPE_CONNECTED) {
if (peer->connection_type != CONNECTION_TYPE_CONNECTED || peer->sessionContext == NULL) {
libp2p_peer_connect(&context->ipfsNode->identity->private_key, peer, context->ipfsNode->peerstore, context->ipfsNode->repo->config->datastore, 10);
if(peer->connection_type != CONNECTION_TYPE_CONNECTED)
return 0;