summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/imports.c
diff options
context:
space:
mode:
authorSiavash Eliasi <[email protected]>2013-12-03 21:50:00 -0700
committerBrian Paul <[email protected]>2013-12-04 07:31:27 -0700
commitf0cc59d68a9f5231e8e2111393a1834858820735 (patch)
treee8261356dc2405630122615badac6777ae760c81 /src/mesa/main/imports.c
parent267679be84de5bc9d2bd0fccb1712bc5cddb6be7 (diff)
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 <[email protected]>
Diffstat (limited to 'src/mesa/main/imports.c')
-rw-r--r--src/mesa/main/imports.c14
1 files changed, 9 insertions, 5 deletions
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
}