From 0360be49f5018dead60b0d2fd637d828420c830e Mon Sep 17 00:00:00 2001 From: Kent Mein Date: Tue, 24 Oct 2006 15:17:39 +0000 Subject: This patch is the first of many to follow that deals with various problems reported by klockwork.com who was very nice and has offered to provide free source code analisys for us. This one deals with freeing memory for an object when there is an error. (The function allocated memory intending to return it but then ran into problems, and was forgetting to free it before it returned NULL) Kent --- intern/bsp/intern/BSP_CSGMesh.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'intern/bsp') diff --git a/intern/bsp/intern/BSP_CSGMesh.cpp b/intern/bsp/intern/BSP_CSGMesh.cpp index 73db00b17a1..36f00868240 100755 --- a/intern/bsp/intern/BSP_CSGMesh.cpp +++ b/intern/bsp/intern/BSP_CSGMesh.cpp @@ -30,10 +30,6 @@ */ -#ifdef HAVE_CONFIG_H -#include -#endif - #include "BSP_CSGMesh.h" #include "MT_assert.h" #include "CTR_TaggedSetOps.h" @@ -78,23 +74,39 @@ NewCopy( if (m_edges != NULL) { mesh->m_edges = new vector(*m_edges); - if (mesh->m_edges == NULL) return NULL; + if (mesh->m_edges == NULL) { + delete mesh; + return NULL; + } } if (m_verts != NULL) { mesh->m_verts = new vector(*m_verts); - if (mesh->m_verts == NULL) return NULL; + if (mesh->m_verts == NULL) { + if (m_edges != NULL) free(mesh->m_edges); + delete mesh; + return NULL; + } } if (m_faces != NULL) { mesh->m_faces = new vector(*m_faces); - if (mesh->m_faces == NULL) return NULL; + if (mesh->m_faces == NULL) { + delete mesh; + return NULL; + } } if (m_fv_data != NULL) { mesh->m_fv_data = new BSP_CSGUserData(*m_fv_data); - if (mesh->m_fv_data == NULL) return NULL; + if (mesh->m_fv_data == NULL) { + delete mesh; + return NULL; + } } if (m_face_data != NULL) { mesh->m_face_data = new BSP_CSGUserData(*m_face_data); - if (mesh->m_face_data == NULL) return NULL; + if (mesh->m_face_data == NULL) { + delete mesh; + return NULL; + } } return mesh; @@ -889,5 +901,3 @@ CountTriangles( return sum; } - - -- cgit v1.2.3