From f0cc59d68a9f5231e8e2111393a1834858820735 Mon Sep 17 00:00:00 2001 From: Siavash Eliasi Date: Tue, 3 Dec 2013 21:50:00 -0700 Subject: mesa: modified _mesa_align_free() to accept NULL pointer So that it acts like ordinary free(). This lets us remove a bunch of if statements where the function is called. v2: - Avoiding compile error on MSVC and possible warnings on other compilers. - Added comment regards passing NULL pointer being safe. Reviewed-by: Brian Paul --- src/mesa/main/imports.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/mesa/main/imports.c') diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 277e9476a66..4afe156b031 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -168,6 +168,8 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment) * \param ptr pointer to the memory to be freed. * The actual address to free is stored in the word immediately before the * address the client sees. + * Note that it is legal to pass NULL pointer to this function and will be + * handled accordingly. */ void _mesa_align_free(void *ptr) @@ -177,9 +179,11 @@ _mesa_align_free(void *ptr) #elif defined(_WIN32) && defined(_MSC_VER) _aligned_free(ptr); #else - void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); - void *realAddr = *cubbyHole; - free(realAddr); + if (ptr) { + void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); + void *realAddr = *cubbyHole; + free(realAddr); + } #endif /* defined(HAVE_POSIX_MEMALIGN) */ } @@ -199,8 +203,8 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize, if (newBuf && oldBuffer && copySize > 0) { memcpy(newBuf, oldBuffer, copySize); } - if (oldBuffer) - _mesa_align_free(oldBuffer); + + _mesa_align_free(oldBuffer); return newBuf; #endif } -- cgit v1.2.3