diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-02-15 17:04:28 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-02-15 17:07:48 +0300 |
commit | 2e9105cc964a157458663fa8102601e3d6ac90e3 (patch) | |
tree | 4605027577bc17d7d6c0815c76f740d807a1ef7f /source/blender/blenlib | |
parent | 35567d563dbc481657772f3484facd6e524e32d7 (diff) |
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.)!
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/storage.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 38a15ab0a6d..05b6d6daf27 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); } |