Package: libg3d
Severity: normal

Hello I attach a patch for a few memory leaks I found in the libg3d library.

I tried my best to have a comprehensible patch but do not hesitate to ask 
questions about it.

thanks

I used this command line to find thoses memory leaks.

G_SLICE=always-malloc G_DEBUG=gc-friendly,resident-modules valgrind 
--leak-check=full --show-reachable=yes --track-origins=yes 
--suppressions=gtk.suppression  my-program

Frederic

Ps: should I send it also to the upstream ?


-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.32-trunk-686 (SMP w/1 CPU core)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Description: Upstream changes introduced in version 0.0.8-9
 This patch has been created by dpkg-source during the package build.
 Here's the last changelog entry, hopefully it gives details on why
 those changes were made:
 .
 libg3d (0.0.8-9) unstable; urgency=low
 .
   * Correct spelling errors found by lintian
   * debian/copyright: Update copyright years
   * Upgraded to policy 3.8.4, no changes required
   * debian/patches:
     - Identify modules by the ending .so instead of .la (Closes: #568797)
 .
 The person named in the Author field signed this changelog entry.
Author: Picca Frédéric-Emmanuel <[email protected]>
Bug-Debian: http://bugs.debian.org/568797

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- libg3d-0.0.8.orig/src/material.c
+++ libg3d-0.0.8/src/material.c
@@ -36,5 +36,6 @@ G3DMaterial *g3d_material_new(void)
 
 void g3d_material_free(G3DMaterial *material)
 {
+       g_free(material->name);
        g_free(material);
 }
--- libg3d-0.0.8.orig/src/object.c
+++ libg3d-0.0.8/src/object.c
@@ -44,6 +44,7 @@ void g3d_object_free(G3DObject *object)
        while(slist != NULL)
        {
                mat = (G3DMaterial*)slist->data;
+               g3d_material_free(mat);
                snext = slist->next;
                g_slist_free_1(slist);
                slist = snext;
@@ -67,7 +68,8 @@ void g3d_object_free(G3DObject *object)
        if(object->_indices != NULL) g_free(object->_indices);
        if(object->_materials != NULL) g_free(object->_materials);
        if(object->_flags != NULL) g_free(object->_flags);
-
+       if(object->_tex_images != NULL) g_free(object->_tex_images);
+       if(object->_tex_coords != NULL) g3d_vector_free(object->_tex_coords);
        g_free(object);
 }
 
--- libg3d-0.0.8.orig/src/plugins.c
+++ libg3d-0.0.8/src/plugins.c
@@ -32,13 +32,12 @@
 
 static void plugins_free_plugin(G3DPlugin *plugin)
 {
-       if(plugin->name)
-               g_free(plugin->name);
-       if(plugin->path)
-               g_free(plugin->path);
-       if(plugin->extensions)
-               g_strfreev(plugin->extensions);
+       if(!plugin)
+               return;
 
+       g_free(plugin->name);
+       g_free(plugin->path);
+       g_strfreev(plugin->extensions);
        if(plugin->module)
                g_module_close(plugin->module);
 
--- libg3d-0.0.8.orig/plugins/image/img_gdkpixbuf.c
+++ libg3d-0.0.8/plugins/image/img_gdkpixbuf.c
@@ -108,16 +108,23 @@ gchar **plugin_extensions(G3DContext *co
        gchar *extensions = g_strdup("");
        gchar **retval;
        gchar *tmp;
+       gchar *ext;
+       gchar **exts;
        GSList *fitem;
+       GSList *list;
        GdkPixbufFormat *format;
 
-       fitem = gdk_pixbuf_get_formats();
+       list = fitem = gdk_pixbuf_get_formats();
        while(fitem)
        {
                format = (GdkPixbufFormat *)fitem->data;
+               exts = gdk_pixbuf_format_get_extensions(format);
+               ext = g_strjoinv(":", exts);
                tmp = g_strdup_printf("%s%s%s", extensions,
-                       strlen(extensions) ? ":" : "",
-                       g_strjoinv(":", 
gdk_pixbuf_format_get_extensions(format)));
+                                     strlen(extensions) ? ":" : "",
+                                     ext);
+               g_strfreev(exts);
+               g_free(ext);
                g_free(extensions);
                extensions = tmp;
                fitem = fitem->next;
@@ -125,6 +132,8 @@ gchar **plugin_extensions(G3DContext *co
 
        retval = g_strsplit(extensions, ":", 0);
        g_free(extensions);
+       g_slist_free(list);
+
        return retval;
 }
 
--- libg3d-0.0.8.orig/plugins/import/imp_obj/imp_obj.c
+++ libg3d-0.0.8/plugins/import/imp_obj/imp_obj.c
@@ -164,6 +164,7 @@ gboolean plugin_load_model_from_stream(G
                                                /* next one if # of vertices < 
3 */
                                                if(face->vertex_count < 3) {
                                                        g3d_face_free(face);
+                                                       g_strfreev(vstrs);
                                                        continue;
                                                }
 
@@ -180,6 +181,7 @@ gboolean plugin_load_model_from_stream(G
                                                if(object == NULL) {
                                                        g_warning("error: face 
before object");
                                                        g3d_face_free(face);
+                                                       g_strfreev(vstrs);
                                                        return FALSE;
                                                }
 
--- libg3d-0.0.8.orig/plugins/import/imp_ldraw/imp_ldraw_color.h
+++ libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw_color.h
@@ -25,6 +25,7 @@
 #include "imp_ldraw_types.h"
 
 gboolean ldraw_color_init(LDrawLibrary *lib);
+void ldraw_color_cleanup(LDrawLibrary *lib);
 G3DMaterial *ldraw_color_lookup(LDrawLibrary *lib, guint32 colid);
 
 #endif /* _IMP_LDRAW_COLOR_H */
--- libg3d-0.0.8.orig/plugins/import/imp_ldraw/imp_ldraw_color.c
+++ libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw_color.c
@@ -103,6 +103,21 @@ gboolean ldraw_color_init(LDrawLibrary *
        return TRUE;
 }
 
+void ldraw_color_cleanup(LDrawLibrary *lib)
+{
+       GSList *plist;
+
+       g_hash_table_destroy(lib->colordb);
+
+       plist = lib->colorlist;
+       while(plist)
+       {
+               g3d_material_free((G3DMaterial *)plist->data);
+               plist = plist->next;
+       }
+       g_slist_free(lib->colorlist);
+}
+
 G3DMaterial *ldraw_color_lookup(LDrawLibrary *lib, guint32 colid)
 {
        G3DMaterial *material;
--- libg3d-0.0.8.orig/plugins/import/imp_ldraw/imp_ldraw_library.c
+++ libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw_library.c
@@ -114,6 +114,7 @@ void ldraw_library_cleanup(LDrawLibrary
                ldraw_part_free(part);
        }
        g_hash_table_destroy(lib->partdb);
+       ldraw_color_cleanup(lib);
        g_free(lib);
 }
 

Reply via email to