summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Santos <thiagossantos@gmail.com>2016-11-26 09:48:46 -0300
committerThiago Santos <thiagossantos@gmail.com>2016-12-05 20:58:57 -0300
commitda2faecb55dfb4cbec77e537b3850a36913f1f50 (patch)
tree1b95e753d4127eef662a38f87f4105c922c8abd9
parent6926d783fe4e446fc513af7198b4ca60cbbd8cf8 (diff)
souphttpsrc: avoid leaking context structuregst-cookies
Reorganize how post-context is checked to avoid leaking a context structure if we create one but are not going to post it.
-rw-r--r--ext/soup/gstsouphttpsrc.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/ext/soup/gstsouphttpsrc.c b/ext/soup/gstsouphttpsrc.c
index 15ac65285..da050bfd6 100644
--- a/ext/soup/gstsouphttpsrc.c
+++ b/ext/soup/gstsouphttpsrc.c
@@ -1120,8 +1120,8 @@ gst_soup_http_src_ensure_session_data (GstSoupHTTPSrc * src)
}
/* if some data wasn't correctly fetched from the context, prepare to emit a new context message */
- if (!src->gstcookie_jar || !src->user_agent || !src->extra_headers
- || !src->referer) {
+ if (src->post_context && (!src->gstcookie_jar || !src->user_agent ||
+ !src->extra_headers || !src->referer)) {
gboolean new_context = FALSE;
if (!context) {
context = gst_context_new ("http", FALSE);
@@ -1143,15 +1143,19 @@ gst_soup_http_src_ensure_session_data (GstSoupHTTPSrc * src)
}
}
+ /* From this point onwards, if we have a context_structure it means we should
+ * post a context */
+
/* fallback to default user-agent if none was found in the context */
if (!src->user_agent) {
src->user_agent = g_strdup (DEFAULT_USER_AGENT);
- gst_structure_set (context_structure, "user-agent", G_TYPE_STRING,
- src->user_agent, NULL);
+ if (context_structure)
+ gst_structure_set (context_structure, "user-agent", G_TYPE_STRING,
+ src->user_agent, NULL);
}
/* use an empty cookie jar if none was found in the context */
- if (!src->gstcookie_jar) {
+ if (context_structure && !src->gstcookie_jar) {
src->gstcookie_jar = gst_http_cookie_jar_new ();
gst_structure_set (context_structure, "cookie-jar", GST_TYPE_OBJECT,
src->gstcookie_jar, NULL);
@@ -1159,6 +1163,9 @@ gst_soup_http_src_ensure_session_data (GstSoupHTTPSrc * src)
if (!src->cookie_jar) {
src->cookie_jar = soup_cookie_jar_new ();
+ }
+
+ if (src->gstcookie_jar) {
g_signal_connect (src->cookie_jar, "changed",
(GCallback) _cookie_jar_changed, src);
g_signal_connect (src->gstcookie_jar, "changed",
@@ -1168,7 +1175,7 @@ gst_soup_http_src_ensure_session_data (GstSoupHTTPSrc * src)
}
/* emit the context if any session data was updated */
- if (src->post_context && context_structure != NULL) {
+ if (context_structure != NULL) {
GstMessage *msg =
gst_message_new_have_context (GST_OBJECT_CAST (src), context);
gst_element_post_message (GST_ELEMENT_CAST (src), msg);