From 996687cfce1c60944ccb01fe8579a4b593b120d5 Mon Sep 17 00:00:00 2001 From: John Jones Date: Thu, 5 Oct 2017 13:52:30 -0500 Subject: [PATCH] Better fix for memory allocation issue with unixfs --- unixfs/unixfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/unixfs/unixfs.c b/unixfs/unixfs.c index 1bde4b6..c50637a 100644 --- a/unixfs/unixfs.c +++ b/unixfs/unixfs.c @@ -141,13 +141,11 @@ int ipfs_unixfs_add_data(unsigned char* data, size_t data_length, struct UnixFS* // debug: display hash size_t b58size = 100; 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; + if (b58key != NULL) { + 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); + free(b58key); } - 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); - free(b58key); return 1;