Bad alloc was not being checked

This commit is contained in:
John Jones 2017-10-05 13:49:08 -05:00
parent 99ffd120e8
commit 9c63ed1315
2 changed files with 5 additions and 1 deletions

View file

@ -44,5 +44,5 @@ function body {
fi fi
kill -9 $daemon_id kill -9 $daemon_id
exit $retVal return $retVal
} }

View file

@ -141,6 +141,10 @@ int ipfs_unixfs_add_data(unsigned char* data, size_t data_length, struct UnixFS*
// debug: display hash // debug: display hash
size_t b58size = 100; size_t b58size = 100;
uint8_t *b58key = (uint8_t *) malloc(b58size); uint8_t *b58key = (uint8_t *) malloc(b58size);
if (b58key == NULL) {
libp2p_logger_error("unixfs", "add_data: Unable to allocate memory for key.\n");
return 0;
}
libp2p_crypto_encoding_base58_encode(unix_fs->hash, unix_fs->hash_length, &b58key, &b58size); libp2p_crypto_encoding_base58_encode(unix_fs->hash, unix_fs->hash_length, &b58key, &b58size);
libp2p_logger_debug("unixfs", "Saving hash of %s to unixfs object.\n", b58key); libp2p_logger_debug("unixfs", "Saving hash of %s to unixfs object.\n", b58key);
free(b58key); free(b58key);