diff options
-rw-r--r-- | src/lib.c | 17 | ||||
-rw-r--r-- | src/main.c | 6 |
2 files changed, 19 insertions, 4 deletions
@@ -31,6 +31,13 @@ invoke_g_hash_table_remove (TranscodeServerCtx *ctx) return FALSE; } +static gboolean +invoke_g_free_client_context (TranscodeClientCtx *ctx) +{ + g_free (ctx); + return FALSE; +} + gboolean stp_on_gst_bus_message (GstBus *bus, GstMessage *msg, @@ -132,6 +139,7 @@ stp_cleanup_transcode_client_ctx (TranscodeClientCtx *ctx) stp_print_status (">>> Doing client cleanup."); g_source_remove (ctx->timeout_handler_id); + ctx->timeout_handler_id = 0; server_ctx->clients = g_list_remove (server_ctx->clients, ctx); @@ -160,9 +168,16 @@ stp_disconnect_cleanup_client (TranscodeClientCtx *ctx) soup_message_body_complete (ctx->msg->response_body); g_source_remove (ctx->timeout_handler_id); + ctx->timeout_handler_id = 0; /* Don't call the "finished" handler and do a double-free */ g_signal_handler_disconnect (ctx->msg, ctx->finished_handler_id); - g_free (ctx); + + /* There might still be functions which use the ctx waiting + * to be invoked on the next main context dispatch, so we + * free this at the end of all those dispatches. */ + g_main_context_invoke_full (NULL, G_PRIORITY_LOW, + (GSourceFunc)invoke_g_free_client_context, + ctx, NULL); } /* Returns a copy of the streamheader GstBuffer */ @@ -124,9 +124,9 @@ invoke_write_client_chunk (TranscodeClientCtx *ctx) stp_print_status ("*"); /* XXX: If samples are coming in too quickly, this can get invoked - * after the client has disconnected and the SoupMessage is invalid - * So, we check if the msg is still a msg before trying to append. */ - if (G_UNLIKELY (!SOUP_IS_MESSAGE (ctx->msg))) + * after the client has disconnected and the SoupMessage is invalid. + * When the client disconnects, timeout_handler_id is set to 0. */ + if (G_UNLIKELY (ctx->timeout_handler_id == 0)) return FALSE; g_signal_emit_by_name (ctx->appsink, "pull-sample", &sample); |