From e33b2e5908a0c2c8e11744c7aab3a00d4e4376ea Mon Sep 17 00:00:00 2001 From: Erik Walthinsen Date: Sun, 7 Jan 2001 07:45:54 +0000 Subject: [PATCH] more leak fixes Original commit message from CVS: more leak fixes --- gst/gstcaps.c | 17 +++++++------ gst/gstcpu.c | 1 + gst/gstelementfactory.c | 14 +++++------ gst/gstpad.c | 4 +++- gst/gstparse.c | 6 +++-- gst/gstplugin.c | 47 +++++++++++++++++++++++++----------- gst/gstprops.c | 63 +++++++++++++++++++++++++++++++++++++------------ gst/gsttype.c | 4 ++-- 8 files changed, 108 insertions(+), 48 deletions(-) diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 62c933f..736e5de 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -41,13 +41,13 @@ get_type_for_mime (const gchar *mime) typeid = gst_type_find_by_mime (mime); if (typeid == 0) { - GstTypeFactory *factory = g_new0 (GstTypeFactory, 1); + GstTypeFactory factory; // = g_new0 (GstTypeFactory, 1); - factory->mime = g_strdup (mime); - factory->exts = NULL; - factory->typefindfunc = NULL; + factory.mime = g_strdup (mime); + factory.exts = NULL; + factory.typefindfunc = NULL; - typeid = gst_type_register (factory); + typeid = gst_type_register (&factory); } return typeid; } @@ -401,13 +401,16 @@ gst_caps_load_thyself (xmlNodePtr parent) { GstCaps *caps = g_new0 (GstCaps, 1); xmlNodePtr field = parent->childs; + gchar *content; while (field) { if (!strcmp (field->name, "name")) { - caps->name = g_strdup (xmlNodeGetContent (field)); + caps->name = xmlNodeGetContent (field); } if (!strcmp (field->name, "type")) { - caps->id = get_type_for_mime (xmlNodeGetContent (field)); + content = xmlNodeGetContent (field); + caps->id = get_type_for_mime (content); + g_free (content); } else if (!strcmp (field->name, "properties")) { caps->properties = gst_props_load_thyself (field); diff --git a/gst/gstcpu.c b/gst/gstcpu.c index 44dc708..22a77d0 100644 --- a/gst/gstcpu.c +++ b/gst/gstcpu.c @@ -71,6 +71,7 @@ _gst_cpu_initialize (void) } GST_INFO (GST_CAT_GST_INIT, "CPU features: %s",featurelist); + g_free(featurelist); } GstCPUFlags diff --git a/gst/gstelementfactory.c b/gst/gstelementfactory.c index 2a78492..a028df2 100644 --- a/gst/gstelementfactory.c +++ b/gst/gstelementfactory.c @@ -393,25 +393,25 @@ gst_elementfactory_load_thyself (xmlNodePtr parent) while (children) { if (!strcmp(children->name, "name")) { - factory->name = g_strdup(xmlNodeGetContent(children)); + factory->name = xmlNodeGetContent(children); } if (!strcmp(children->name, "longname")) { - factory->details->longname = g_strdup(xmlNodeGetContent(children)); + factory->details->longname = xmlNodeGetContent(children); } if (!strcmp(children->name, "class")) { - factory->details->klass = g_strdup(xmlNodeGetContent(children)); + factory->details->klass = xmlNodeGetContent(children); } if (!strcmp(children->name, "description")) { - factory->details->description = g_strdup(xmlNodeGetContent(children)); + factory->details->description = xmlNodeGetContent(children); } if (!strcmp(children->name, "version")) { - factory->details->version = g_strdup(xmlNodeGetContent(children)); + factory->details->version = xmlNodeGetContent(children); } if (!strcmp(children->name, "author")) { - factory->details->author = g_strdup(xmlNodeGetContent(children)); + factory->details->author = xmlNodeGetContent(children); } if (!strcmp(children->name, "copyright")) { - factory->details->copyright = g_strdup(xmlNodeGetContent(children)); + factory->details->copyright = xmlNodeGetContent(children); } if (!strcmp(children->name, "padtemplate")) { GstPadTemplate *template; diff --git a/gst/gstpad.c b/gst/gstpad.c index bf01562..f769c03 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -1011,7 +1011,7 @@ gst_padtemplate_load_thyself (xmlNodePtr parent) while (field) { if (!strcmp(field->name, "nametemplate")) { - factory->name_template = g_strdup(xmlNodeGetContent(field)); + factory->name_template = xmlNodeGetContent(field); } if (!strcmp(field->name, "direction")) { gchar *value = xmlNodeGetContent(field); @@ -1023,6 +1023,7 @@ gst_padtemplate_load_thyself (xmlNodePtr parent) else if (!strcmp(value, "src")) { factory->direction = GST_PAD_SRC; } + g_free (value); } if (!strcmp(field->name, "presence")) { gchar *value = xmlNodeGetContent(field); @@ -1033,6 +1034,7 @@ gst_padtemplate_load_thyself (xmlNodePtr parent) else if (!strcmp(value, "sometimes")) { factory->presence = GST_PAD_SOMETIMES; } + g_free (value); } else if (!strcmp(field->name, "caps")) { factory->caps = g_list_append(factory->caps, gst_caps_load_thyself (field)); diff --git a/gst/gstparse.c b/gst/gstparse.c index 4c92e34..6a23c72 100644 --- a/gst/gstparse.c +++ b/gst/gstparse.c @@ -86,7 +86,7 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr GList *pads; gint elementcount = 0; gint retval = 0; - + priv->binlevel++; if (GST_IS_PIPELINE(parent)) { closingchar = '\0';DEBUG("in pipeline "); } @@ -205,7 +205,9 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr } else { // we have an element DEBUG("attempting to create element '%s'\n",arg); - element = gst_elementfactory_make(arg,gst_parse_unique_name(arg,priv)); + ptr = gst_parse_unique_name(arg,priv); + element = gst_elementfactory_make(arg,ptr); + g_free(ptr); if (!element) { fprintf(stderr,"Couldn't create a '%s', no such element or need to run gstraemer-register?\n",arg); // exit(-1); diff --git a/gst/gstplugin.c b/gst/gstplugin.c index ea96095..7fe609e 100644 --- a/gst/gstplugin.c +++ b/gst/gstplugin.c @@ -90,6 +90,8 @@ _gst_plugin_initialize (void) return; } gst_plugin_load_thyself (doc->root); + + xmlFreeDoc (doc); } static time_t @@ -155,6 +157,7 @@ gst_plugin_load_recurse (gchar *directory, gchar *name) DIR *dir; struct dirent *dirent; gboolean loaded = FALSE; + gchar *dirname; //g_print("recursive load of '%s' in '%s'\n", name, directory); dir = opendir(directory); @@ -162,9 +165,13 @@ gst_plugin_load_recurse (gchar *directory, gchar *name) while ((dirent = readdir(dir))) { /* don't want to recurse in place or backwards */ if (strcmp(dirent->d_name,".") && strcmp(dirent->d_name,"..")) { - loaded = gst_plugin_load_recurse(g_strjoin("/",directory,dirent->d_name, - NULL),name); - if (loaded && name) return TRUE; + dirname = g_strjoin("/",directory,dirent->d_name,NULL); + loaded = gst_plugin_load_recurse(dirname,name); + g_free(dirname); + if (loaded && name) { + closedir(dir); + return TRUE; + } } } closedir(dir); @@ -267,6 +274,7 @@ gst_plugin_load (const gchar *name) GList *path; gchar *libspath; GstPlugin *plugin; + gchar *pluginname; //g_print("attempting to load plugin '%s'\n",name); @@ -276,19 +284,28 @@ gst_plugin_load (const gchar *name) path = _gst_plugin_paths; while (path != NULL) { - if (gst_plugin_load_absolute(g_module_build_path(path->data,name))) + pluginname = g_module_build_path(path->data,name); + if (gst_plugin_load_absolute(pluginname)) { + g_free(pluginname); return TRUE; + } + g_free(pluginname); libspath = g_strconcat(path->data,"/.libs",NULL); //g_print("trying to load '%s'\n",g_module_build_path(libspath,name)); - if (gst_plugin_load_absolute(g_module_build_path(libspath,name))) { - g_free(libspath); + pluginname = g_module_build_path(libspath,name); + g_free(libspath); + if (gst_plugin_load_absolute(pluginname)) { + g_free(pluginname); return TRUE; } - g_free(libspath); + g_free(pluginname); //g_print("trying to load '%s' from '%s'\n",name,path->data); - if (gst_plugin_load_recurse(path->data,g_module_build_path("",name))) { + pluginname = g_module_build_path("",name); + if (gst_plugin_load_recurse(path->data,pluginname)) { + g_free(pluginname); return TRUE; } + g_free(pluginname); path = g_list_next(path); } return FALSE; @@ -738,6 +755,7 @@ gst_plugin_load_thyself (xmlNodePtr parent) xmlNodePtr kinderen; gint elementcount = 0; gint typecount = 0; + gchar *pluginname; kinderen = parent->childs; // Dutch invasion :-) while (kinderen) { @@ -750,20 +768,21 @@ gst_plugin_load_thyself (xmlNodePtr parent) while (field) { if (!strcmp(field->name, "name")) { - if (gst_plugin_find(xmlNodeGetContent(field))) { + pluginname = xmlNodeGetContent(field); + if (gst_plugin_find(pluginname)) { + g_free(pluginname); g_free(plugin); plugin = NULL; break; - } - else { - plugin->name = g_strdup(xmlNodeGetContent(field)); + } else { + plugin->name = pluginname; } } else if (!strcmp(field->name, "longname")) { - plugin->longname = g_strdup(xmlNodeGetContent(field)); + plugin->longname = xmlNodeGetContent(field); } else if (!strcmp(field->name, "filename")) { - plugin->filename = g_strdup(xmlNodeGetContent(field)); + plugin->filename = xmlNodeGetContent(field); } else if (!strcmp(field->name, "element")) { GstElementFactory *factory = gst_elementfactory_load_thyself(field); diff --git a/gst/gstprops.c b/gst/gstprops.c index 754c78d1..87d37aa 100644 --- a/gst/gstprops.c +++ b/gst/gstprops.c @@ -469,24 +469,35 @@ static xmlNodePtr gst_props_save_thyself_func (GstPropsEntry *entry, xmlNodePtr parent) { xmlNodePtr subtree; + gchar *str; switch (entry->propstype) { case GST_PROPS_INT_ID_NUM: subtree = xmlNewChild (parent, NULL, "int", NULL); xmlNewProp (subtree, "name", g_quark_to_string (entry->propid)); - xmlNewProp (subtree, "value", g_strdup_printf ("%d", entry->data.int_data)); + str = g_strdup_printf ("%d", entry->data.int_data); + xmlNewProp (subtree, "value", str); + g_free(str); break; case GST_PROPS_INT_RANGE_ID_NUM: subtree = xmlNewChild (parent, NULL, "range", NULL); xmlNewProp (subtree, "name", g_quark_to_string (entry->propid)); - xmlNewProp (subtree, "min", g_strdup_printf ("%d", entry->data.int_range_data.min)); - xmlNewProp (subtree, "max", g_strdup_printf ("%d", entry->data.int_range_data.max)); + str = g_strdup_printf ("%d", entry->data.int_range_data.min); + xmlNewProp (subtree, "min", str); + g_free(str); + str = g_strdup_printf ("%d", entry->data.int_range_data.max); + xmlNewProp (subtree, "max", str); + g_free(str); break; case GST_PROPS_FOURCC_ID_NUM: - xmlAddChild (parent, xmlNewComment (g_strdup_printf ("%4.4s", (gchar *)&entry->data.fourcc_data))); + str = g_strdup_printf ("%4.4s", (gchar *)&entry->data.fourcc_data); + xmlAddChild (parent, xmlNewComment (str)); + g_free(str); subtree = xmlNewChild (parent, NULL, "fourcc", NULL); xmlNewProp (subtree, "name", g_quark_to_string (entry->propid)); - xmlNewProp (subtree, "hexvalue", g_strdup_printf ("%08x", entry->data.fourcc_data)); + str = g_strdup_printf ("%08x", entry->data.fourcc_data); + xmlNewProp (subtree, "hexvalue", str); + g_free(str); break; case GST_PROPS_BOOL_ID_NUM: subtree = xmlNewChild (parent, NULL, "boolean", NULL); @@ -541,30 +552,49 @@ static GstPropsEntry* gst_props_load_thyself_func (xmlNodePtr field) { GstPropsEntry *entry; + gchar *prop; entry = g_new0 (GstPropsEntry, 1); if (!strcmp(field->name, "int")) { entry->propstype = GST_PROPS_INT_ID_NUM; - entry->propid = g_quark_from_string (xmlGetProp(field, "name")); - sscanf (xmlGetProp(field, "value"), "%d", &entry->data.int_data); + prop = xmlGetProp(field, "name"); + entry->propid = g_quark_from_string (prop); + g_free (prop); + prop = xmlGetProp(field, "value"); + sscanf (prop, "%d", &entry->data.int_data); + g_free (prop); } else if (!strcmp(field->name, "range")) { entry->propstype = GST_PROPS_INT_RANGE_ID_NUM; - entry->propid = g_quark_from_string (xmlGetProp(field, "name")); - sscanf (xmlGetProp(field, "min"), "%d", &entry->data.int_range_data.min); - sscanf (xmlGetProp(field, "max"), "%d", &entry->data.int_range_data.max); + prop = xmlGetProp(field, "name"); + entry->propid = g_quark_from_string (prop); + g_free (prop); + prop = xmlGetProp (field, "min"); + sscanf (prop, "%d", &entry->data.int_range_data.min); + g_free (prop); + prop = xmlGetProp (field, "min"); + sscanf (prop, "%d", &entry->data.int_range_data.max); + g_free (prop); } else if (!strcmp(field->name, "boolean")) { entry->propstype = GST_PROPS_BOOL_ID_NUM; - entry->propid = g_quark_from_string (xmlGetProp(field, "name")); - if (!strcmp (xmlGetProp(field, "value"), "false")) entry->data.bool_data = 0; + prop = xmlGetProp(field, "name"); + entry->propid = g_quark_from_string (prop); + g_free (prop); + prop = xmlGetProp (field, "value"); + if (!strcmp (prop, "false")) entry->data.bool_data = 0; else entry->data.bool_data = 1; + g_free (prop); } else if (!strcmp(field->name, "fourcc")) { entry->propstype = GST_PROPS_FOURCC_ID_NUM; - entry->propid = g_quark_from_string (xmlGetProp(field, "name")); - sscanf (xmlGetProp(field, "hexvalue"), "%08x", &entry->data.fourcc_data); + prop = xmlGetProp(field, "name"); + entry->propid = g_quark_from_string (prop); + g_free (prop); + prop = xmlGetProp (field, "hexvalue"); + sscanf (prop, "%08x", &entry->data.fourcc_data); + g_free (prop); } return entry; @@ -583,6 +613,7 @@ gst_props_load_thyself (xmlNodePtr parent) { GstProps *props = g_new0 (GstProps, 1); xmlNodePtr field = parent->childs; + gchar *prop; while (field) { if (!strcmp (field->name, "list")) { @@ -591,7 +622,9 @@ gst_props_load_thyself (xmlNodePtr parent) entry = g_new0 (GstPropsEntry, 1); entry->propstype = GST_PROPS_LIST_ID_NUM; - entry->propid = g_quark_from_string (xmlGetProp(field, "name")); + prop = xmlGetProp (field, "name"); + entry->propid = g_quark_from_string (prop); + g_free (prop); while (subfield) { GstPropsEntry *subentry = gst_props_load_thyself_func (subfield); diff --git a/gst/gsttype.c b/gst/gsttype.c index c7367ec..af21fae 100644 --- a/gst/gsttype.c +++ b/gst/gsttype.c @@ -272,10 +272,10 @@ gst_typefactory_load_thyself (xmlNodePtr parent) while (field) { if (!strcmp (field->name, "mime")) { - factory->mime = g_strdup (xmlNodeGetContent (field)); + factory->mime = xmlNodeGetContent (field); } else if (!strcmp (field->name, "extensions")) { - factory->exts = g_strdup (xmlNodeGetContent (field)); + factory->exts = xmlNodeGetContent (field); } else if (!strcmp (field->name, "typefind")) { factory->typefindfunc = gst_type_typefind_dummy; -- 2.7.4