]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Fixing segmentation faults because of missing initializations
[meshlink] / src / meshlink.c
index 7ea3e440b0f941d773c06eba53a267b0199b7508..2e6a37cc3ad1cdb4a8658abd1b06ec2f86eb331e 100644 (file)
@@ -737,6 +737,10 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) {
        meshlink_handle_t *mesh = xzalloc(sizeof *mesh);
        mesh->confbase = xstrdup(confbase);
        if (usingname) mesh->name = xstrdup(name);
+       mesh->self = new_node();
+       mesh->self->connection = new_connection();
+       if(!read_ecdsa_private_key(mesh))
+               return false;
        pthread_mutex_init ( &(mesh->outpacketqueue_mutex), NULL);
        pthread_mutex_init ( &(mesh->nodes_mutex), NULL);
        mesh->threadstarted = false;
@@ -773,11 +777,6 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) {
        WSAStartup(MAKEWORD(2, 2), &wsa_state);
 #endif
 
-       // Setup up everything
-       // TODO: we should not open listening sockets yet
-
-       if(!setup_network(mesh))
-               return meshlink_close(mesh), NULL;
 
        return mesh;
 }
@@ -800,6 +799,10 @@ bool meshlink_start(meshlink_handle_t *mesh) {
                fprintf(stderr, "No name given!\n");
                return false;
        }
+       // Setup up everything
+
+       if(!setup_network(mesh))
+               return meshlink_close(mesh), NULL;
 
        // Start the main thread
 
@@ -837,6 +840,8 @@ void meshlink_close(meshlink_handle_t *mesh) {
        exit_configuration(&mesh->config);
        event_loop_exit(&mesh->loop);
 
+       free(mesh);
+
 #ifdef HAVE_MINGW
        WSACleanup();
 #endif