From da5b04a0c214dffd46b180afa9cd553ff839e13c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 3 Aug 2013 18:05:30 +0000 Subject: [PATCH] fix for over-allocation in BKE_pbvh_search_gather, BKE_pbvh_gather_proxies, each element was having the size of PBVHNode allocated rather then the size of a pointer (8 vs 184 bytes here) --- source/blender/blenkernel/intern/pbvh.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index a0cc37dcf3f..9290ccc8c5d 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -753,7 +753,7 @@ void BKE_pbvh_search_gather(PBVH *bvh, PBVHNode ***r_array, int *r_tot) { PBVHIter iter; - PBVHNode **array = NULL, **newarray, *node; + PBVHNode **array = NULL, *node; int tot = 0, space = 0; pbvh_iter_begin(&iter, bvh, scb, search_data); @@ -763,14 +763,7 @@ void BKE_pbvh_search_gather(PBVH *bvh, if (tot == space) { /* resize array if needed */ space = (tot == 0) ? 32 : space * 2; - newarray = MEM_callocN(sizeof(PBVHNode) * space, "PBVHNodeSearch"); - - if (array) { - memcpy(newarray, array, sizeof(PBVHNode) * tot); - MEM_freeN(array); - } - - array = newarray; + array = MEM_recallocN_id(array, sizeof(PBVHNode *) * space, __func__); } array[tot] = node; @@ -1807,7 +1800,7 @@ void BKE_pbvh_node_free_proxies(PBVHNode *node) void BKE_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot) { - PBVHNode **array = NULL, **newarray, *node; + PBVHNode **array = NULL, *node; int tot = 0, space = 0; int n; @@ -1818,14 +1811,7 @@ void BKE_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot) if (tot == space) { /* resize array if needed */ space = (tot == 0) ? 32 : space * 2; - newarray = MEM_callocN(sizeof(PBVHNode) * space, "BKE_pbvh_gather_proxies"); - - if (array) { - memcpy(newarray, array, sizeof(PBVHNode) * tot); - MEM_freeN(array); - } - - array = newarray; + array = MEM_recallocN_id(array, sizeof(PBVHNode *) * space, __func__); } array[tot] = node;