diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-07-21 05:24:50 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-07-21 05:25:20 +0300 |
commit | 50fe187443b8fdd9aa462e51bc49dcaa8f33b67a (patch) | |
tree | eb3f111f7359b5ecc72055247af9229ab2f2ad70 /source | |
parent | 731d9f0bfa40cabd33abcbabc37acca9bc5837eb (diff) |
Cleanup: improve comment for disabled readfile allocation naming
Also allocate the required amount instead of a fixed size.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 23 |
1 files 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); } |