summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2014-07-17 14:25:09 (GMT)
committerNirbheek Chauhan <nirbheek@centricular.com>2014-07-17 14:25:09 (GMT)
commit79ccdc559490bcdab6529dc74bba5d694e8d5913 (patch)
tree2d644e9063fa11f62cb3419037b3ca6727fc8f97
parent0a8517326c0bfb3416997aa24c525e9ce92fdd84 (diff)
downloadsoup-transcoding-proxy-79ccdc559490bcdab6529dc74bba5d694e8d5913.zip
soup-transcoding-proxy-79ccdc559490bcdab6529dc74bba5d694e8d5913.tar.gz
server: Fix another potential crash
-rw-r--r--src/lib.c17
-rw-r--r--src/main.c6
2 files changed, 19 insertions, 4 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 */
diff --git a/src/main.c b/src/main.c
index 2d3e537..e9be17d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);