ssb: Fix a leaked request and a shutdown error.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 18m35s

This commit is contained in:
Cory McWilliams 2024-10-04 12:39:39 -04:00
parent 90e000c18e
commit 7c36a543da

View File

@ -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) if (flags & k_ssb_rpc_flag_end_error)
{ {
tf_ssb_connection_remove_request(connection, -request_number);
return; return;
} }
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection); 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) 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; blob_wants_work_t* work = user_data;
JSContext* context = tf_ssb_connection_get_context(connection); if (!tf_ssb_is_shutting_down(tf_ssb_connection_get_ssb(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); JSContext* context = tf_ssb_connection_get_context(connection);
JS_SetPropertyStr(context, message, work->out_id[i], JS_NewInt32(context, -1)); tf_ssb_blob_wants_t* blob_wants = tf_ssb_connection_get_blob_wants_state(connection);
tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_stream, -blob_wants->request_number, NULL, message, NULL, NULL, NULL); for (int i = 0; i < work->out_id_count; i++)
JS_FreeValue(context, message); {
blob_wants->wants_sent++; JSValue message = JS_NewObject(context);
} JS_SetPropertyStr(context, message, work->out_id[i], JS_NewInt32(context, -1));
if (work->out_id_count) 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);
snprintf(blob_wants->last_id, sizeof(blob_wants->last_id), "%s", work->out_id[work->out_id_count - 1]); 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); tf_free(work);
} }