From 3423e73cece2657e4e0008a60f2f9d0ade618fbe Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Wed, 17 Jul 2024 01:46:46 +0800 Subject: [PATCH] gallivm: orcjit: keep the ownership of tm for LPJit The ownership of the TargetMachine object is released when LPJit singleton is constructed, leads to a slight memory loss detectable. Keep the ownership by saving the unique pointer as another class member named tm_unique. Signed-off-by: Icenowy Zheng Reviewed-by: Dave Airlie Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp index 32792138220..9821e3176d8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp +++ b/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp @@ -279,6 +279,7 @@ private: static LPJit* jit; std::unique_ptr lljit; + std::unique_ptr tm_unique; /* avoid name conflict */ unsigned jit_dylib_count; @@ -318,7 +319,8 @@ LPJit::LPJit() :jit_dylib_count(0) { init_native_targets(); JITTargetMachineBuilder JTMB = create_jtdb(); - tm = wrap(ExitOnErr(JTMB.createTargetMachine()).release()); + tm_unique = ExitOnErr(JTMB.createTargetMachine()); + tm = wrap(tm_unique.get()); /* Create an LLJIT instance with an ObjectLinkingLayer (JITLINK) * or RuntimeDyld as the base layer.