From 30bec331af03e5d754a5f916c14f928617bfeaa4 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Mon, 2 Feb 2004 20:25:02 +0000 Subject: [PATCH] Fix memory leaks: Original commit message from CVS: reviewed by: David Schleef Fix memory leaks: * gst/gstcaps.c: (gst_caps_to_string): * gst/registries/gstxmlregistry.c: (gst_xml_registry_add_path_list_func), (gst_xml_registry_parse_padtemplate): --- ChangeLog | 10 ++++++++++ gst/gstcaps.c | 9 +++++++-- gst/registries/gstxmlregistry.c | 18 +++++++++++------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index af2cae7af2..233fd83543 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-02-02 Jon Trowbridge + + reviewed by: David Schleef + + Fix memory leaks: + * gst/gstcaps.c: (gst_caps_to_string): + * gst/registries/gstxmlregistry.c: + (gst_xml_registry_add_path_list_func), + (gst_xml_registry_parse_padtemplate): + 2004-02-02 Thomas Vander Stichele * gst/gstelement.c: (gst_element_default_error): diff --git a/gst/gstcaps.c b/gst/gstcaps.c index e2cab93c69..676c835d73 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -1026,6 +1026,7 @@ gchar *gst_caps_to_string (const GstCaps *caps) int i; GstStructure *structure; GString *s; + char *sstr; /* NOTE: This function is potentially called by the debug system, * so any calls to gst_log() (and GST_DEBUG(), GST_LOG(), etc.) @@ -1046,13 +1047,17 @@ gchar *gst_caps_to_string (const GstCaps *caps) } s = g_string_new(""); structure = gst_caps_get_structure (caps, 0); - g_string_append(s, gst_structure_to_string(structure)); + sstr = gst_structure_to_string(structure); + g_string_append(s, sstr); + g_free(sstr); for(i=1;istructs->len;i++){ structure = gst_caps_get_structure (caps, i); g_string_append(s, "; "); - g_string_append(s, gst_structure_to_string(structure)); + sstr = gst_structure_to_string(structure); + g_string_append(s, sstr); + g_free(sstr); } return g_string_free(s, FALSE); diff --git a/gst/registries/gstxmlregistry.c b/gst/registries/gstxmlregistry.c index 277a5c76ed..e0aae75ccd 100644 --- a/gst/registries/gstxmlregistry.c +++ b/gst/registries/gstxmlregistry.c @@ -375,9 +375,9 @@ gst_xml_registry_get_perms_func (GstXMLRegistry *registry) static void gst_xml_registry_add_path_list_func (GstXMLRegistry *registry) { - FILE *reg; + FILE *reg = NULL; GMarkupParseContext *context; - gchar *text; + gchar *text = NULL; gssize size; GError *error = NULL; @@ -385,7 +385,7 @@ gst_xml_registry_add_path_list_func (GstXMLRegistry *registry) registry, NULL); if (! (reg = fopen (registry->location, "r"))) { - return; + goto finished; } /* slightly allocate more as gmarkup reads too much */ @@ -399,9 +399,7 @@ gst_xml_registry_add_path_list_func (GstXMLRegistry *registry) if (error) { GST_ERROR ("parsing registry %s: %s\n", registry->location, error->message); - g_free (text); - fclose (reg); - return; + goto finished; } if (registry->state == GST_XML_REGISTRY_PATHS_DONE) @@ -410,7 +408,12 @@ gst_xml_registry_add_path_list_func (GstXMLRegistry *registry) size = fread (text, 1, BLOCK_SIZE, reg); } - fclose (reg); + finished: + + g_markup_parse_context_free (context); + + if (reg) + fclose (reg); g_free (text); } @@ -837,6 +840,7 @@ gst_xml_registry_parse_padtemplate (GMarkupParseContext *context, const gchar *t char *s; s = g_strndup (text, text_len); + g_assert (registry->caps == NULL); registry->caps = gst_caps_from_string (s); if (registry->caps == NULL) { g_critical ("Could not parse caps: length %d, content: %*s\n", text_len, text_len, text);