aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/imports.c
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/main/imports.c')
-rw-r--r--mesalib/src/mesa/main/imports.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/mesalib/src/mesa/main/imports.c b/mesalib/src/mesa/main/imports.c
index 277e9476a..4afe156b0 100644
--- a/mesalib/src/mesa/main/imports.c
+++ b/mesalib/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
}