forked from cory/tildefriends
Fix more memory leaks and ssb shutdown order issues.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4825 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
17
src/ssb.c
17
src/ssb.c
@ -211,6 +211,7 @@ typedef struct _tf_ssb_t
|
||||
|
||||
bool verbose;
|
||||
bool store_debug_messages;
|
||||
bool shutting_down;
|
||||
|
||||
int messages_stored;
|
||||
int blobs_stored;
|
||||
@ -219,6 +220,7 @@ typedef struct _tf_ssb_t
|
||||
|
||||
tf_ssb_connection_t* connections;
|
||||
int connections_count;
|
||||
int connection_ref_count;
|
||||
int request_count;
|
||||
|
||||
tf_ssb_connections_t* connections_tracker;
|
||||
@ -1921,6 +1923,11 @@ static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const ch
|
||||
connection->debug_messages[i] = NULL;
|
||||
}
|
||||
|
||||
if (--connection->ssb->connection_ref_count == 0 &&
|
||||
connection->ssb->shutting_down)
|
||||
{
|
||||
tf_ssb_destroy(connection->ssb);
|
||||
}
|
||||
tf_free(connection);
|
||||
}
|
||||
}
|
||||
@ -2368,6 +2375,7 @@ static void _tf_ssb_on_timer_close(uv_handle_t* handle)
|
||||
void tf_ssb_destroy(tf_ssb_t* ssb)
|
||||
{
|
||||
tf_printf("tf_ssb_destroy\n");
|
||||
ssb->shutting_down = true;
|
||||
tf_ssb_connections_destroy(ssb->connections_tracker);
|
||||
ssb->connections_tracker = NULL;
|
||||
|
||||
@ -2540,7 +2548,11 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
|
||||
tf_free((void*)ssb->db_path);
|
||||
tf_free(ssb->room_name);
|
||||
ssb->room_name = NULL;
|
||||
tf_free(ssb);
|
||||
|
||||
if (ssb->connection_ref_count == 0)
|
||||
{
|
||||
tf_free(ssb);
|
||||
}
|
||||
}
|
||||
|
||||
void tf_ssb_run(tf_ssb_t* ssb)
|
||||
@ -2590,6 +2602,7 @@ tf_ssb_connection_t* tf_ssb_connection_create(tf_ssb_t* ssb, const char* host, c
|
||||
|
||||
JSContext* context = ssb->context;
|
||||
tf_ssb_connection_t* connection = tf_malloc(sizeof(tf_ssb_connection_t));
|
||||
ssb->connection_ref_count++;
|
||||
memset(connection, 0, sizeof(*connection));
|
||||
snprintf(connection->name, sizeof(connection->name), "cli%d", s_connection_index++);
|
||||
connection->ssb = ssb;
|
||||
@ -2665,6 +2678,7 @@ tf_ssb_connection_t* tf_ssb_connection_tunnel_create(tf_ssb_t* ssb, const char*
|
||||
|
||||
JSContext* context = ssb->context;
|
||||
tf_ssb_connection_t* tunnel = tf_malloc(sizeof(tf_ssb_connection_t));
|
||||
ssb->connection_ref_count++;
|
||||
memset(tunnel, 0, sizeof(*tunnel));
|
||||
snprintf(tunnel->name, sizeof(tunnel->name), "tun%d", s_tunnel_index++);
|
||||
tunnel->ssb = ssb;
|
||||
@ -2768,6 +2782,7 @@ static void _tf_ssb_on_connection(uv_stream_t* stream, int status)
|
||||
}
|
||||
|
||||
tf_ssb_connection_t* connection = tf_malloc(sizeof(tf_ssb_connection_t));
|
||||
ssb->connection_ref_count++;
|
||||
memset(connection, 0, sizeof(*connection));
|
||||
snprintf(connection->name, sizeof(connection->name), "srv%d", s_connection_index++);
|
||||
connection->ssb = ssb;
|
||||
|
Reference in New Issue
Block a user