Now correctly initializing Cid variable, and checking after decoding

This commit is contained in:
jmjatlanta 2017-10-12 13:04:23 -05:00
parent 8cdaf919fe
commit a315af8534

View file

@ -163,8 +163,12 @@ int ipfs_core_http_process_object(struct IpfsNode* local_node, struct HttpReques
// do an object_get // do an object_get
if (request->arguments->total == 1) { if (request->arguments->total == 1) {
char* hash = (char*)libp2p_utils_vector_get(request->arguments, 0); char* hash = (char*)libp2p_utils_vector_get(request->arguments, 0);
struct Cid* cid; struct Cid* cid = NULL;
ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid); if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid)) {
ipfs_cid_free(cid);
cid = NULL;
return 0;
}
*response = ipfs_core_http_response_new(); *response = ipfs_core_http_response_new();
struct HttpResponse* res = *response; struct HttpResponse* res = *response;
res->content_type = "application/json"; res->content_type = "application/json";
@ -181,7 +185,7 @@ int ipfs_core_http_process_dht_provide(struct IpfsNode* local_node, struct HttpR
int failedCount = 0; int failedCount = 0;
for (int i = 0; i < request->arguments->total; i++) { for (int i = 0; i < request->arguments->total; i++) {
char* hash = (char*)libp2p_utils_vector_get(request->arguments, i); char* hash = (char*)libp2p_utils_vector_get(request->arguments, i);
struct Cid* cid; struct Cid* cid = NULL;
if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid)) { if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid)) {
ipfs_cid_free(cid); ipfs_cid_free(cid);
cid = NULL; cid = NULL;
@ -253,7 +257,7 @@ int ipfs_core_http_process_dht_get(struct IpfsNode* local_node, struct HttpReque
for (int i = 0; i < request->arguments->total; i++) { for (int i = 0; i < request->arguments->total; i++) {
char* hash = (char*)libp2p_utils_vector_get(request->arguments, i); char* hash = (char*)libp2p_utils_vector_get(request->arguments, i);
struct Cid* cid; struct Cid* cid = NULL;
if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid)) { if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid)) {
ipfs_cid_free(cid); ipfs_cid_free(cid);
cid = NULL; cid = NULL;