diff options
author | Kent Mein <mein@cs.umn.edu> | 2006-10-24 19:17:39 +0400 |
---|---|---|
committer | Kent Mein <mein@cs.umn.edu> | 2006-10-24 19:17:39 +0400 |
commit | 0360be49f5018dead60b0d2fd637d828420c830e (patch) | |
tree | bb88d86099b118a10ce1d32a9a74f14b6e5a653a /intern | |
parent | 9d67a597bc2bff427c958e013d83f763386223f7 (diff) |
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
Diffstat (limited to 'intern')
-rwxr-xr-x | intern/bsp/intern/BSP_CSGMesh.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
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 <config.h> -#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<BSP_MEdge>(*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<BSP_MVertex>(*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<BSP_MFace>(*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; } - - |