Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-02-20 13:28:58 +0300
committerCampbell Barton <campbell@blender.org>2022-02-21 04:01:32 +0300
commit2554ef986a8ccd1dc245478f99524dc68f8af435 (patch)
tree031d4bac9911d2dece826c603f4a9c6619031185 /source/blender/blenloader
parente93a8c4f74d854b6e2b42cb10651333faed8f280 (diff)
readfile: free & reallocate arrays in oldnewmap_clear
Even though the size of the map was set back to DEFAULT_SIZE_EXP, the underlying arrays were left unchained. In some cases this caused further expansions to result in an unusual reallocation pattern where MEM_reallocN would run expand the entries into an array that was in fact the same size.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/intern/readfile.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 7dd35203a89..9539436cf69 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -320,15 +320,22 @@ static void oldnewmap_increase_size(OldNewMap *onm)
/* Public OldNewMap API */
-static OldNewMap *oldnewmap_new(void)
+static void oldnewmap_init_data(OldNewMap *onm, const int capacity_exp)
{
- OldNewMap *onm = MEM_callocN(sizeof(*onm), "OldNewMap");
+ memset(onm, 0x0, sizeof(*onm));
- onm->capacity_exp = DEFAULT_SIZE_EXP;
+ onm->capacity_exp = capacity_exp;
onm->entries = MEM_malloc_arrayN(
ENTRIES_CAPACITY(onm), sizeof(*onm->entries), "OldNewMap.entries");
onm->map = MEM_malloc_arrayN(MAP_CAPACITY(onm), sizeof(*onm->map), "OldNewMap.map");
oldnewmap_clear_map(onm);
+}
+
+static OldNewMap *oldnewmap_new(void)
+{
+ OldNewMap *onm = MEM_mallocN(sizeof(*onm), "OldNewMap");
+
+ oldnewmap_init_data(onm, DEFAULT_SIZE_EXP);
return onm;
}
@@ -395,9 +402,10 @@ static void oldnewmap_clear(OldNewMap *onm)
}
}
- onm->capacity_exp = DEFAULT_SIZE_EXP;
- oldnewmap_clear_map(onm);
- onm->nentries = 0;
+ MEM_freeN(onm->entries);
+ MEM_freeN(onm->map);
+
+ oldnewmap_init_data(onm, DEFAULT_SIZE_EXP);
}
static void oldnewmap_free(OldNewMap *onm)