Package: libg3d / 0.0.8-26

Fix-memory-leaks-in-plugins.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
From: Sven Eckelmann <sven@narfation.org>
Date: Sat, 12 Sep 2009 15:23:40 +0200
Subject: Fix memory leaks in plugins

Bug: https://mail.gna.org/public/libg3d-devel/2009-02/msg00000.html
---
 plugins/import/imp_ac3d/imp_ac3d.c | 13 +++++++------
 plugins/import/imp_dpm/imp_dpm.c   |  6 ++++++
 plugins/import/imp_flt/imp_flt.c   |  1 +
 plugins/import/imp_md3/imp_md3.c   |  1 +
 plugins/import/imp_obj/imp_obj.c   |  6 +++++-
 5 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/plugins/import/imp_ac3d/imp_ac3d.c b/plugins/import/imp_ac3d/imp_ac3d.c
index 3653b07..46b4800 100644
--- a/plugins/import/imp_ac3d/imp_ac3d.c
+++ b/plugins/import/imp_ac3d/imp_ac3d.c
@@ -32,6 +32,7 @@
 #include <g3d/stream.h>
 #include <g3d/material.h>
 #include <g3d/texture.h>
+#include <g3d/face.h>
 #include <g3d/debug.h>
 
 #define AC3D_FLAG_ACC    0x01
@@ -119,6 +120,7 @@ gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream,
 			g_debug("\\(0) Object (line %d)", rowcnt);
 			ac3d_read_object(stream, context, model, buffer, transform, flags,
 				&(model->objects), &rowcnt, 1);
+			g_free(transform);
 		}
 		else
 		{
@@ -330,8 +332,10 @@ static gint32 ac3d_read_object(G3DStream *stream, G3DContext *context,
 						/* normal face */
 						for(i = 0; i < face->vertex_count; i ++)
 						{
-							if(!g3d_stream_read_line(stream, buffer, 2048))
+							if(!g3d_stream_read_line(stream, buffer, 2048)) {
+								g3d_face_free(face);
 								return 0;
+							}
 							*rowcnt += 1;
 
 							if(sscanf(buffer, "%u %f %f",
@@ -350,16 +354,13 @@ static gint32 ac3d_read_object(G3DStream *stream, G3DContext *context,
 
 							face->tex_vertex_data[i * 2 + 0] += texoffu;
 							face->tex_vertex_data[i * 2 + 1] += texoffv;
-
-#if 0
-							face->tex_coords[i * 2 + 0] *= texscaleu;
-							face->tex_coords[i * 2 + 1] *= texscalev;
-#endif
 						}
 
 						if(face->material && (face->vertex_count >= 3))
 							object->faces =
 								g_slist_prepend(object->faces, face);
+						else
+							g3d_face_free(face);
 
 					} /* not .acc */
 					else
diff --git a/plugins/import/imp_dpm/imp_dpm.c b/plugins/import/imp_dpm/imp_dpm.c
index 7f616e8..a704505 100644
--- a/plugins/import/imp_dpm/imp_dpm.c
+++ b/plugins/import/imp_dpm/imp_dpm.c
@@ -26,6 +26,7 @@
 #include <string.h>
 
 #include <g3d/types.h>
+#include <g3d/object.h>
 #include <g3d/material.h>
 #include <g3d/texture.h>
 #include <g3d/stream.h>
@@ -136,8 +137,13 @@ gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream,
 
 		/* read triangles */
 		/* TODO */
+
+		g_free(normals);
 	}
 
+	/* FIXME: insert object into model instead */
+	g3d_object_free(object);
+
 	return TRUE;
 }
 
diff --git a/plugins/import/imp_flt/imp_flt.c b/plugins/import/imp_flt/imp_flt.c
index 847b881..4ceee27 100644
--- a/plugins/import/imp_flt/imp_flt.c
+++ b/plugins/import/imp_flt/imp_flt.c
@@ -64,6 +64,7 @@ gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream,
 
 		if(opcode == 0) {
 			/* end of file or error */
+			g_free(ld);
 			break;
 		}
 
diff --git a/plugins/import/imp_md3/imp_md3.c b/plugins/import/imp_md3/imp_md3.c
index 7bacf5a..0f407b3 100644
--- a/plugins/import/imp_md3/imp_md3.c
+++ b/plugins/import/imp_md3/imp_md3.c
@@ -253,6 +253,7 @@ gboolean md3_read_mesh(G3DStream *stream, G3DContext *context, G3DModel *model)
 	if((nvertex == 0) || (ntris == 0)) {
 		g_warning("MD3: %u vertices, %u triangles", nvertex, ntris);
 		g3d_stream_seek(stream, off_start + mlength, G_SEEK_SET);
+		g3d_object_free(object);
 		return FALSE;
 	}
 
diff --git a/plugins/import/imp_obj/imp_obj.c b/plugins/import/imp_obj/imp_obj.c
index e131afd..466754e 100644
--- a/plugins/import/imp_obj/imp_obj.c
+++ b/plugins/import/imp_obj/imp_obj.c
@@ -29,6 +29,7 @@
 #include <g3d/context.h>
 #include <g3d/types.h>
 #include <g3d/material.h>
+#include <g3d/face.h>
 #include <g3d/stream.h>
 
 #define OBJ_USE_GROUPING 0
@@ -161,8 +162,10 @@ gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream,
 						face->vertex_count = num_v - 1;
 
 						/* next one if # of vertices < 3 */
-						if(face->vertex_count < 3)
+						if(face->vertex_count < 3) {
+							g3d_face_free(face);
 							continue;
+						}
 
 						/* calculate object-local vertex offset, indices
 						 * in .obj files are absolute */
@@ -176,6 +179,7 @@ gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream,
 #endif
 						if(object == NULL) {
 							g_warning("error: face before object");
+							g3d_face_free(face);
 							return FALSE;
 						}