diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2007-09-04 02:13:39 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2007-09-04 02:13:39 +0000 |
commit | 1a2d580a1262fb08d36e0c4be0e51d28be3c2eac (patch) | |
tree | 7a115c1001a6edf8525bd4291f5ecd56c394f969 /lib | |
parent | a72f7504ba9e12d1c263ece83c04bb486963b9ba (diff) | |
download | netpbm-mirror-1a2d580a1262fb08d36e0c4be0e51d28be3c2eac.tar.gz netpbm-mirror-1a2d580a1262fb08d36e0c4be0e51d28be3c2eac.tar.xz netpbm-mirror-1a2d580a1262fb08d36e0c4be0e51d28be3c2eac.zip |
make REALLOCARRAY free memory if it fails
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@400 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/mallocvar.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/util/mallocvar.h b/lib/util/mallocvar.h index a26d007b..e5b7b1ea 100644 --- a/lib/util/mallocvar.h +++ b/lib/util/mallocvar.h @@ -57,11 +57,22 @@ static __inline__ void reallocProduct(void ** const blockP, unsigned int const factor1, unsigned int const factor2) { + + void * const oldBlockP = *blockP; + + void * newBlockP; if (UINT_MAX / factor2 < factor1) - *blockP = NULL; + newBlockP = NULL; else - *blockP = realloc(*blockP, factor1 * factor2); + newBlockP = realloc(oldBlockP, factor1 * factor2); + + if (newBlockP) + *blockP = newBlockP; + else { + free(oldBlockP); + *blockP = NULL; + } } |