mojoshader_common.c
changeset 1188 25000edc0176
parent 1180 8abc040525ed
child 1195 f4ef8606c68d
--- a/mojoshader_common.c	Thu May 17 13:05:09 2018 -0400
+++ b/mojoshader_common.c	Wed May 23 11:07:59 2018 -0400
@@ -4,8 +4,16 @@
 
 // Convenience functions for allocators...
 #if !MOJOSHADER_FORCE_ALLOCATOR
-void * MOJOSHADERCALL MOJOSHADER_internal_malloc(int bytes, void *d) { return malloc(bytes); }
-void MOJOSHADERCALL MOJOSHADER_internal_free(void *ptr, void *d) { free(ptr); }
+static char zeromalloc = 0;
+void * MOJOSHADERCALL MOJOSHADER_internal_malloc(int bytes, void *d)
+{
+    return (bytes == 0) ? &zeromalloc : malloc(bytes);
+} // MOJOSHADER_internal_malloc
+void MOJOSHADERCALL MOJOSHADER_internal_free(void *ptr, void *d)
+{
+    if ((ptr != &zeromalloc) && (ptr != NULL))
+        free(ptr);
+} // MOJOSHADER_internal_free
 #endif
 
 MOJOSHADER_error MOJOSHADER_out_of_mem_error = {