Package: libg3d / 0.0.8-20

fix-memory-leaks-2.patch Patch series | download
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
Description: Fix memory leaks
Forwarded: https://mail.gna.org/public/libg3d-devel/2010-02/msg00000.html
Author: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
Bug-Debian: http://bugs.debian.org/570084

---
diff --git a/plugins/image/img_gdkpixbuf.c b/plugins/image/img_gdkpixbuf.c
index 931c9fdf9c19059bc01570985ee29189e5f2fae0..5a4984d8242c49029fa66e2914623582c9d622a4 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 269f6c6d6a418b3a68cb474c8092cac427838d39..7623f5edb8747a2840eeb9df7b4337731b160cd7 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 e5844de6c81b6b61fa88e70a07b15c49af1dfff1..941d0c10db6754018df6212f3a67e21903e1f6d5 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 aa07cdb52a45e8a7db380a8bba9ae7ffaf96433f..7e12128e7222eadcf16c952cea6ba0109d90b834 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 466754e7a16bc3441cf19b39a88b0fe1f433b3ae..6d7fe2f20dc5adccdfccb163e88170800a6d09c2 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 ad03d62b8bc355ad213d7404c16328f9625a4f1e..e9f529ee606ae7e4dfeab69546d1ca37a465f4dc 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 202fbfa58151eaff1493984b900b822760fa87ae..42afe7cc4f3e34424b3e44fb2516f85107fb581e 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 f8d282ba28519e84cbcab97f38b94634d93c6a72..044950df7296bd9c470c610df43a98ac1650462b 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);