[Bf-blender-cvs] [2e9105c] master: Cleanup: BLI_listdir (direntry): get rid of usage of raw malloc/free here.

Bastien Montagne noreply at git.blender.org
Sun Feb 15 15:10:24 CET 2015


Commit: 2e9105cc964a157458663fa8102601e3d6ac90e3
Author: Bastien Montagne
Date:   Sun Feb 15 15:04:28 2015 +0100
Branches: master
https://developer.blender.org/rB2e9105cc964a157458663fa8102601e3d6ac90e3

Cleanup: BLI_listdir (direntry): get rid of usage of raw malloc/free here.

No reason at all not to use MEM_xxx as everywhere else, especially confusing
when members of direntry **are** MEM_-allocated (relname, etc.)!

===================================================================

M	source/blender/blenlib/intern/storage.c
M	source/blender/blenloader/BLO_readfile.h

===================================================================

diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 38a15ab..05b6d6d 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -219,7 +219,6 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
 	DIR *dir;
 
 	if ((dir = opendir(dirname)) != NULL) {
-
 		const struct dirent *fname;
 		while ((fname = readdir(dir)) != NULL) {
 			struct dirlink * const dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
@@ -231,20 +230,19 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
 		}
 
 		if (newnum) {
-
 			if (dir_ctx->files) {
-				void * const tmp = realloc(dir_ctx->files, (dir_ctx->nrfiles + newnum) * sizeof(struct direntry));
+				void * const tmp = MEM_reallocN(dir_ctx->files, (dir_ctx->nrfiles + newnum) * sizeof(struct direntry));
 				if (tmp) {
 					dir_ctx->files = (struct direntry *)tmp;
 				}
 				else { /* realloc fail */
-					free(dir_ctx->files);
+					MEM_freeN(dir_ctx->files);
 					dir_ctx->files = NULL;
 				}
 			}
 			
 			if (dir_ctx->files == NULL)
-				dir_ctx->files = (struct direntry *)malloc(newnum * sizeof(struct direntry));
+				dir_ctx->files = (struct direntry *)MEM_mallocN(newnum * sizeof(struct direntry), __func__);
 
 			if (dir_ctx->files) {
 				struct dirlink * dlink = (struct dirlink *) dirbase.first;
@@ -405,7 +403,7 @@ unsigned int BLI_filelist_dir_contents(const char *dirname,  struct direntry **f
 	else {
 		// keep blender happy. Blender stores this in a variable
 		// where 0 has special meaning.....
-		*filelist = malloc(sizeof(struct direntry));
+		*filelist = MEM_mallocN(sizeof(**filelist), __func__);
 	}
 
 	return dir_ctx.nrfiles;
@@ -422,7 +420,7 @@ void BLI_filelist_duplicate(
 {
 	unsigned int i;
 
-	*dest_filelist = malloc(sizeof(**dest_filelist) * (size_t)(nrentries));
+	*dest_filelist = MEM_mallocN(sizeof(**dest_filelist) * (size_t)(nrentries), __func__);
 	for (i = 0; i < nrentries; ++i) {
 		struct direntry * const src = &src_filelist[i];
 		struct direntry *dest = &(*dest_filelist)[i];
@@ -461,7 +459,7 @@ void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries, void (
 			free_poin(entry->poin);
 	}
 
-	free(filelist);
+	MEM_freeN(filelist);
 }
 
 
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 7a6107a..419d8c0 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -37,7 +37,6 @@ extern "C" {
 #endif
 
 struct bScreen;
-struct direntry;
 struct LinkNode;
 struct Main;
 struct MemFile;




More information about the Bf-blender-cvs mailing list