Check for NULL in Free(). trunk
authorRyan C. Gordon <icculus@icculus.org>
Fri, 04 Apr 2008 14:46:51 -0400
branchtrunk
changeset 99 20d0bb294e9e
parent 98 08b137beb1e3
child 100 2b88649b6f98
Check for NULL in Free(). This is just convenience, in case of braindead allocators.
mojoshader.c
--- a/mojoshader.c	Fri Apr 04 14:44:05 2008 -0400
+++ b/mojoshader.c	Fri Apr 04 14:46:51 2008 -0400
@@ -349,7 +349,9 @@
 
 static inline void Free(Context *ctx, void *ptr)
 {
-    ctx->free(ptr, ctx->malloc_data);
+    // check for NULL in case of dumb free() impl.
+    if (ptr != NULL)
+        ctx->free(ptr, ctx->malloc_data);
 } // Free
 
 
@@ -3605,10 +3607,8 @@
     // check again, in case build_output ran out of memory.
     if (isfail(ctx))
     {
-        if (output != NULL)
-            Free(ctx, output);
-        if (uniforms != NULL)
-            Free(ctx, uniforms);
+        Free(ctx, output);
+        Free(ctx, uniforms);
         retval->error = ctx->failstr;  // we recycle.  :)
         ctx->failstr = NULL;  // don't let this get free()'d too soon.
     } // if