d3d11: Fix possible leaks after compiling shaders
authorEthan Lee <flibitijibibo@flibitijibibo.com>
Fri, 02 Oct 2020 14:48:29 -0400
changeset 1305 1fc6f843168f
parent 1304 d68910d81b6e
child 1306 0c0304e7d215
d3d11: Fix possible leaks after compiling shaders
mojoshader_d3d11.c
--- a/mojoshader_d3d11.c	Wed Sep 30 22:51:53 2020 -0400
+++ b/mojoshader_d3d11.c	Fri Oct 02 14:48:29 2020 -0400
@@ -504,10 +504,12 @@
                                  pshader->parseData->mainfn, "ps_4_0",
                                  D3D_SKIP_OPT, 0, &blob, &blob);
 
+    if (needs_free)
+        ctx->free_fn((void *) source, ctx->malloc_data);
+
     if (result < 0)
     {
         set_error((const char *) ID3D10Blob_GetBufferPointer(blob));
-        ctx->free_fn((void *) source, ctx->malloc_data);
         return NULL;
     } // if
 
@@ -517,8 +519,6 @@
                                    NULL, &retval);
 
     ID3D10Blob_Release(blob);
-    if (needs_free)
-        ctx->free_fn((void *) source, ctx->malloc_data);
     return retval;
 } // compilePixelShader
 
@@ -836,6 +836,8 @@
     vshader->shaderMaps[vshader->numMaps].vertex.layoutHash = inputLayoutHash;
     ID3D11VertexShader *vs = compileVertexShader(vshader, newSource,
                                                  srcLength, &blob);
+    if (newSource != origSource)
+        ctx->free_fn((void *) newSource, ctx->malloc_data);
     vshader->shaderMaps[ctx->vertexShader->numMaps].val = vs;
     vshader->shaderMaps[ctx->vertexShader->numMaps].vertex.blob = blob;
     ctx->vertexShader->numMaps++;