[Bf-blender-cvs] [50fe187443b] master: Cleanup: improve comment for disabled readfile allocation naming
Campbell Barton
noreply at git.blender.org
Tue Jul 21 04:29:14 CEST 2020
Commit: 50fe187443b8fdd9aa462e51bc49dcaa8f33b67a
Author: Campbell Barton
Date: Tue Jul 21 12:24:50 2020 +1000
Branches: master
https://developer.blender.org/rB50fe187443b8fdd9aa462e51bc49dcaa8f33b67a
Cleanup: improve comment for disabled readfile allocation naming
Also allocate the required amount instead of a fixed size.
===================================================================
M source/blender/blenloader/intern/readfile.c
===================================================================
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);
}
More information about the Bf-blender-cvs
mailing list