diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-28 11:43:21 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-28 11:43:21 +0400 |
commit | f8f7523fb2f38ae03e029ee1d279d5dc3c91390d (patch) | |
tree | 9411bcd207519f1ee332e6dc1677ce63b5d107aa /source/blender/bmesh | |
parent | 3553bf6db02b5e625ea9ee28b624fa6d5cd6d306 (diff) |
fix memory leak in BM_face_copy()
note that this doesnt run when duplicating faces normally, only way to cause this bug I could find was to knife cut a 33+ sided ngon with multi-res applied.
also small improvement not to grow the array but allocate at once if needed.
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_core.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index 756fd742fa6..f38c737b8ac 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -184,34 +184,32 @@ static BMLoop *bm_face_boundary_add(BMesh *bm, BMFace *f, BMVert *startv, BMEdge BMFace *BM_face_copy(BMesh *bm, BMFace *f, const short copyverts, const short copyedges) { - BMEdge **edges = NULL; BMVert **verts = NULL; - BLI_array_staticdeclare(edges, BM_NGON_STACK_SIZE); - BLI_array_staticdeclare(verts, BM_NGON_STACK_SIZE); + BMEdge **edges = NULL; + BLI_array_fixedstack_declare(verts, BM_NGON_STACK_SIZE, f->len, __func__); + BLI_array_fixedstack_declare(edges, BM_NGON_STACK_SIZE, f->len, __func__); BMLoop *l_iter; BMLoop *l_first; BMLoop *l_copy; BMFace *f_copy; int i; - /* BMESH_TODO - grow verts array in one go! (right here) */ l_iter = l_first = BM_FACE_FIRST_LOOP(f); + i = 0; do { if (copyverts) { - BMVert *v = BM_vert_create(bm, l_iter->v->co, l_iter->v); - BLI_array_append(verts, v); + verts[i] = BM_vert_create(bm, l_iter->v->co, l_iter->v); } else { - BLI_array_append(verts, l_iter->v); + verts[i] = l_iter->v; } + i++; } while ((l_iter = l_iter->next) != l_first); - /* BMESH_TODO - grow edges array in one go! (right here) */ l_iter = l_first = BM_FACE_FIRST_LOOP(f); i = 0; do { if (copyedges) { - BMEdge *e; BMVert *v1, *v2; if (l_iter->e->v1 == verts[i]) { @@ -223,13 +221,11 @@ BMFace *BM_face_copy(BMesh *bm, BMFace *f, const short copyverts, const short co v1 = verts[(i + 1) % f->len]; } - e = BM_edge_create(bm, v1, v2, l_iter->e, FALSE); - BLI_array_append(edges, e); + edges[i] = BM_edge_create(bm, v1, v2, l_iter->e, FALSE); } else { - BLI_array_append(edges, l_iter->e); + edges[i] = l_iter->e; } - i++; } while ((l_iter = l_iter->next) != l_first); @@ -243,7 +239,10 @@ BMFace *BM_face_copy(BMesh *bm, BMFace *f, const short copyverts, const short co BM_elem_attrs_copy(bm, bm, l_iter, l_copy); l_copy = l_copy->next; } while ((l_iter = l_iter->next) != l_first); - + + BLI_array_fixedstack_free(verts); + BLI_array_fixedstack_free(edges); + return f_copy; } |