microsoft/clc: Fix test double free in the case of compilation failure
authorJesse Natalie <jenatali@microsoft.com>
Mon, 27 Jun 2022 03:58:24 +0000 (20:58 -0700)
committerMarge Bot <emma+marge@anholt.net>
Mon, 27 Jun 2022 16:54:27 +0000 (16:54 +0000)
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17246>

src/microsoft/clc/compute_test.cpp

index 07543e1..1171e37 100644 (file)
@@ -848,13 +848,14 @@ ComputeTest::configure(Shader &shader,
          throw runtime_error("failed to parse spirv!");
    }
 
-   shader.dxil = std::shared_ptr<clc_dxil_object>(new clc_dxil_object{}, [](clc_dxil_object *dxil)
+   std::unique_ptr<clc_dxil_object> dxil(new clc_dxil_object{});
+   if (!clc_spirv_to_dxil(compiler_ctx, shader.obj.get(), shader.metadata.get(), "main_test", conf, nullptr, &logger, dxil.get()))
+      throw runtime_error("failed to compile kernel!");
+   shader.dxil = std::shared_ptr<clc_dxil_object>(dxil.release(), [](clc_dxil_object *dxil)
       {
          clc_free_dxil_object(dxil);
          delete dxil;
       });
-   if (!clc_spirv_to_dxil(compiler_ctx, shader.obj.get(), shader.metadata.get(), "main_test", conf, nullptr, &logger, shader.dxil.get()))
-      throw runtime_error("failed to compile kernel!");
 }
 
 void