Fixed minor leak in test and more compiler warnings

This commit is contained in:
John Jones 2016-12-14 06:39:06 -05:00
parent bf0cbfb412
commit 88d177cf4a
3 changed files with 16 additions and 0 deletions

View file

@ -27,10 +27,16 @@ int ipfs_cid_protobuf_encode(struct Cid* cid, unsigned char* buffer, size_t buff
int retVal = 0;
if (cid != NULL) {
retVal = protobuf_encode_varint(1, ipfs_cid_message_fields[0], cid->version, buffer, buffer_length, &bytes_used);
if (retVal == 0)
return 0;
*bytes_written += bytes_used;
retVal = protobuf_encode_varint(2, ipfs_cid_message_fields[1], cid->codec, &buffer[*bytes_written], buffer_length - (*bytes_written), &bytes_used);
if (retVal == 0)
return 0;
*bytes_written += bytes_used;
retVal = protobuf_encode_length_delimited(3, ipfs_cid_message_fields[2], (char*)cid->hash, cid->hash_length, &buffer[*bytes_written], buffer_length - (*bytes_written), &bytes_used);
if (retVal == 0)
return 0;
*bytes_written += bytes_used;
}
return 1;

View file

@ -75,12 +75,18 @@ int ipfs_node_link_protobuf_encode(struct NodeLink* link, unsigned char* buffer,
int retVal = 0;
*bytes_written = 0;
retVal = protobuf_encode_length_delimited(1, ipfs_node_link_message_fields[0], link->name, strlen(link->name), &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
if (retVal == 0)
return 0;
*bytes_written += bytes_used;
// cid
size_t cid_size = ipfs_cid_protobuf_encode_size(link->cid);
unsigned char cid_buffer[cid_size];
retVal = ipfs_cid_protobuf_encode(link->cid, cid_buffer, cid_size, &bytes_used);
if (retVal == 0)
return 0;
retVal = protobuf_encode_length_delimited(2, ipfs_node_link_message_fields[1], (char*)&cid_buffer[0], bytes_used, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
if (retVal == 0)
return 0;
*bytes_written += bytes_used;
return 1;
}

View file

@ -6,6 +6,8 @@ int test_node() {
unsigned char * ahash = (unsigned char*)"QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG";
struct NodeLink * mylink;
int retVal = ipfs_node_link_new(name,ahash, &mylink);
if (retVal == 0)
return 0;
//Link Two for testing purposes
char * name2 = "Simo";
@ -83,6 +85,8 @@ l_exit:
ipfs_node_link_free(control);
if (results != NULL)
ipfs_node_link_free(results);
if (buffer != NULL)
free(buffer);
return retVal;
}