small bugfixes, chasing segfault

This commit is contained in:
jmjatlanta 2017-09-25 09:20:51 -05:00
parent 5404fce6ec
commit 4b1cd8cb11
3 changed files with 23 additions and 1 deletions

View file

@ -698,6 +698,20 @@ void *api_listen_thread (void *ptr)
return NULL;
}
struct ApiContext* api_context_new() {
struct ApiContext* context = (struct ApiContext*) malloc(sizeof(struct ApiContext));
if (context != NULL) {
context->conns = NULL;
context->conns_count = 0;
context->ipv4 = 0;
context->max_conns = 0;
context->port = 0;
context->socket = 0;
context->timeout = 0;
}
return context;
}
/**
* Start API interface daemon.
* @param local_node the context
@ -716,6 +730,12 @@ int api_start (struct IpfsNode* local_node, int max_conns, int timeout)
multiaddress_get_ip_address(my_address, &ip);
int port = multiaddress_get_ip_port(my_address);
local_node->api_context = api_context_new();
if (local_node->api_context == NULL) {
multiaddress_free(my_address);
return 0;
}
local_node->api_context->ipv4 = hostname_to_ip(ip); // api is listening only on loopback.
local_node->api_context->port = port;

View file

@ -23,6 +23,7 @@ struct IpfsNode* ipfs_node_new() {
node->providerstore = NULL;
node->repo = NULL;
node->routing = NULL;
node->api_context = NULL;
}
return node;
}
@ -151,7 +152,7 @@ int ipfs_node_offline_new(const char* repo_path, struct IpfsNode** node) {
*/
int ipfs_node_free(struct IpfsNode* node) {
if (node != NULL) {
if (node->api_context->api_thread != NULL)
if (node->api_context != NULL && node->api_context->api_thread != 0)
api_stop(node);
if (node->exchange != NULL) {
node->exchange->Close(node->exchange);

View file

@ -20,6 +20,7 @@ int test_core_api_startup_shutdown() {
test_daemon_start(repo_path);
sleep(3);
// make a client to the api
struct IpfsNode* client_node = NULL;
if (!ipfs_node_offline_new(repo_path, &client_node)) {
goto exit;