1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
From: =?utf-8?q?Picca_Fr=C3=A9d=C3=A9ric-Emmanuel?=
<picca@synchrotron-soleil.fr>
Date: Tue, 16 Feb 2010 12:38:34 +0100
Subject: Fix memory leaks
Forwarded: https://mail.gna.org/public/libg3d-devel/2010-02/msg00000.html
Bug-Debian: https://bugs.debian.org/570084
---
plugins/image/img_gdkpixbuf.c | 15 ++++++++++++---
plugins/import/imp_ldraw/imp_ldraw_color.c | 15 +++++++++++++++
plugins/import/imp_ldraw/imp_ldraw_color.h | 1 +
plugins/import/imp_ldraw/imp_ldraw_library.c | 1 +
plugins/import/imp_obj/imp_obj.c | 2 ++
src/material.c | 1 +
src/object.c | 4 +++-
src/plugins.c | 11 +++++------
8 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/plugins/image/img_gdkpixbuf.c b/plugins/image/img_gdkpixbuf.c
index 931c9fd..5a4984d 100644
--- a/plugins/image/img_gdkpixbuf.c
+++ b/plugins/image/img_gdkpixbuf.c
@@ -108,16 +108,23 @@ gchar **plugin_extensions(G3DContext *context)
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 *context)
retval = g_strsplit(extensions, ":", 0);
g_free(extensions);
+ g_slist_free(list);
+
return retval;
}
diff --git a/plugins/import/imp_ldraw/imp_ldraw_color.c b/plugins/import/imp_ldraw/imp_ldraw_color.c
index 269f6c6..7623f5e 100644
--- a/plugins/import/imp_ldraw/imp_ldraw_color.c
+++ b/plugins/import/imp_ldraw/imp_ldraw_color.c
@@ -103,6 +103,21 @@ gboolean ldraw_color_init(LDrawLibrary *lib)
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;
diff --git a/plugins/import/imp_ldraw/imp_ldraw_color.h b/plugins/import/imp_ldraw/imp_ldraw_color.h
index e5844de..941d0c1 100644
--- a/plugins/import/imp_ldraw/imp_ldraw_color.h
+++ b/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 */
diff --git a/plugins/import/imp_ldraw/imp_ldraw_library.c b/plugins/import/imp_ldraw/imp_ldraw_library.c
index aa07cdb..7e12128 100644
--- a/plugins/import/imp_ldraw/imp_ldraw_library.c
+++ b/plugins/import/imp_ldraw/imp_ldraw_library.c
@@ -114,6 +114,7 @@ void ldraw_library_cleanup(LDrawLibrary *lib)
ldraw_part_free(part);
}
g_hash_table_destroy(lib->partdb);
+ ldraw_color_cleanup(lib);
g_free(lib);
}
diff --git a/plugins/import/imp_obj/imp_obj.c b/plugins/import/imp_obj/imp_obj.c
index 466754e..6d7fe2f 100644
--- a/plugins/import/imp_obj/imp_obj.c
+++ b/plugins/import/imp_obj/imp_obj.c
@@ -164,6 +164,7 @@ gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream,
/* 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(G3DContext *context, G3DStream *stream,
if(object == NULL) {
g_warning("error: face before object");
g3d_face_free(face);
+ g_strfreev(vstrs);
return FALSE;
}
diff --git a/src/material.c b/src/material.c
index ad03d62..e9f529e 100644
--- a/src/material.c
+++ b/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);
}
diff --git a/src/object.c b/src/object.c
index 202fbfa..42afe7c 100644
--- a/src/object.c
+++ b/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);
}
diff --git a/src/plugins.c b/src/plugins.c
index f8d282b..044950d 100644
--- a/src/plugins.c
+++ b/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);
|