From 7c36a543da1e2b4e4849de74b999153c959dbab6 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Fri, 4 Oct 2024 12:39:39 -0400 Subject: [PATCH] ssb: Fix a leaked request and a shutdown error. --- src/ssb.rpc.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/ssb.rpc.c b/src/ssb.rpc.c index 548739a0..3afcfb6e 100644 --- a/src/ssb.rpc.c +++ b/src/ssb.rpc.c @@ -106,6 +106,7 @@ static void _tf_ssb_rpc_blobs_get(tf_ssb_connection_t* connection, uint8_t flags { if (flags & k_ssb_rpc_flag_end_error) { + tf_ssb_connection_remove_request(connection, -request_number); return; } tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection); @@ -255,19 +256,22 @@ static void _tf_ssb_request_blob_wants_work(tf_ssb_connection_t* connection, voi static void _tf_ssb_request_blob_wants_after_work(tf_ssb_connection_t* connection, int result, void* user_data) { blob_wants_work_t* work = user_data; - JSContext* context = tf_ssb_connection_get_context(connection); - tf_ssb_blob_wants_t* blob_wants = tf_ssb_connection_get_blob_wants_state(connection); - for (int i = 0; i < work->out_id_count; i++) + if (!tf_ssb_is_shutting_down(tf_ssb_connection_get_ssb(connection))) { - JSValue message = JS_NewObject(context); - JS_SetPropertyStr(context, message, work->out_id[i], JS_NewInt32(context, -1)); - tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_stream, -blob_wants->request_number, NULL, message, NULL, NULL, NULL); - JS_FreeValue(context, message); - blob_wants->wants_sent++; - } - if (work->out_id_count) - { - snprintf(blob_wants->last_id, sizeof(blob_wants->last_id), "%s", work->out_id[work->out_id_count - 1]); + JSContext* context = tf_ssb_connection_get_context(connection); + tf_ssb_blob_wants_t* blob_wants = tf_ssb_connection_get_blob_wants_state(connection); + for (int i = 0; i < work->out_id_count; i++) + { + JSValue message = JS_NewObject(context); + JS_SetPropertyStr(context, message, work->out_id[i], JS_NewInt32(context, -1)); + tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_stream, -blob_wants->request_number, NULL, message, NULL, NULL, NULL); + JS_FreeValue(context, message); + blob_wants->wants_sent++; + } + if (work->out_id_count) + { + snprintf(blob_wants->last_id, sizeof(blob_wants->last_id), "%s", work->out_id[work->out_id_count - 1]); + } } tf_free(work); }