From 50fe187443b8fdd9aa462e51bc49dcaa8f33b67a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 21 Jul 2020 12:24:50 +1000 Subject: Cleanup: improve comment for disabled readfile allocation naming Also allocate the required amount instead of a fixed size. --- source/blender/blenloader/intern/readfile.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 44a1a6ec44a..8bfab730313 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -8982,18 +8982,23 @@ static BHead *read_data_into_datamap(FileData *fd, BHead *bhead, const char *all bhead = blo_bhead_next(fd, bhead); while (bhead && bhead->code == DATA) { - void *data; + /* The code below is useful for debugging leaks in data read from the blend file. + * Without this the messages only tell us what ID-type the memory came from, + * eg: `Data from OB len 64`, see #dataname. + * With the code below we get the struct-name to help tracking down the leak. + * This is kept disabled as the #malloc for the text always leaks memory. */ #if 0 - /* XXX DUMB DEBUGGING OPTION TO GIVE NAMES for guarded malloc errors */ - short *sp = fd->filesdna->structs[bhead->SDNAnr]; - char *tmp = malloc(100); - allocname = fd->filesdna->types[sp[0]]; - strcpy(tmp, allocname); - data = read_struct(fd, bhead, tmp); -#else - data = read_struct(fd, bhead, allocname); + { + const short *sp = fd->filesdna->structs[bhead->SDNAnr]; + allocname = fd->filesdna->types[sp[0]]; + size_t allocname_size = strlen(allocname) + 1; + char *allocname_buf = malloc(allocname_size); + memcpy(allocname_buf, allocname, allocname_size); + allocname = allocname_buf; + } #endif + void *data = read_struct(fd, bhead, allocname); if (data) { oldnewmap_insert(fd->datamap, bhead->old, data, 0); } -- cgit v1.2.3