summaryrefslogtreecommitdiff
path: root/src/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.c')
-rw-r--r--src/lib.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/lib.c b/src/lib.c
index 062a8be..a986f30 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -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 */