Fixed NULL dereference. trunk
authorRyan C. Gordon <icculus@icculus.org>
Tue, 29 Apr 2008 20:39:04 -0400
branchtrunk
changeset 251 290378a53579
parent 250 b75c08291021
child 252 59a608b65a0a
Fixed NULL dereference. Can happen if fail() happens during the building of uniform/attribute/sample for parseData...you have a NULL array, but we think there are items in the array to free.
mojoshader.c
--- a/mojoshader.c	Tue Apr 29 20:33:02 2008 -0400
+++ b/mojoshader.c	Tue Apr 29 20:39:04 2008 -0400
@@ -4691,17 +4691,26 @@
 
         Free(ctx, output);
 
-        for (i = 0; i < ctx->uniform_count; i++)
-            Free(ctx, (void *) uniforms[i].name);
-        Free(ctx, uniforms);
-
-        for (i = 0; i < attribute_count; i++)
-            Free(ctx, (void *) attributes[i].name);
-        Free(ctx, attributes);
-
-        for (i = 0; i < ctx->sampler_count; i++)
-            Free(ctx, (void *) samplers[i].name);
-        Free(ctx, samplers);
+        if (uniforms != NULL)
+        {
+            for (i = 0; i < ctx->uniform_count; i++)
+                Free(ctx, (void *) uniforms[i].name);
+            Free(ctx, uniforms);
+        } // if
+
+        if (attributes != NULL)
+        {
+            for (i = 0; i < attribute_count; i++)
+                Free(ctx, (void *) attributes[i].name);
+            Free(ctx, attributes);
+        } // if
+
+        if (samplers != NULL)
+        {
+            for (i = 0; i < ctx->sampler_count; i++)
+                Free(ctx, (void *) samplers[i].name);
+            Free(ctx, samplers);
+        } // if
 
         retval->error = ctx->failstr;  // we recycle.  :)
         ctx->failstr = NULL;  // don't let this get free()'d too soon.