[llvm] [orc-rt] Fix memory leak in WrapperFunctionResult. (PR #156795)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 3 21:11:39 PDT 2025
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/156795
Previously `Tmp` could have been left owning a heap-allocated buffer and would not have freed it on destruction (since Tmp was a C orc_rt_WrapperFunctionResult).
This patch removes Tmp and simply resets R before swapping it with Other.R.
>From 9c0c8b2c8be3bffa21a80bfe46679877775bc112 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Thu, 4 Sep 2025 11:17:56 +1000
Subject: [PATCH] [orc-rt] Fix memory leak in WrapperFunctionResult.
Previously `Tmp` could have been left owning a heap-allocated buffer and would
not have freed it on destruction (since Tmp was a C
orc_rt_WrapperFunctionResult).
This patch removes Tmp and simply resets R before swapping it with Other.R.
---
orc-rt/include/orc-rt/WrapperFunctionResult.h | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/orc-rt/include/orc-rt/WrapperFunctionResult.h b/orc-rt/include/orc-rt/WrapperFunctionResult.h
index d3bc132070e86..852202954cca7 100644
--- a/orc-rt/include/orc-rt/WrapperFunctionResult.h
+++ b/orc-rt/include/orc-rt/WrapperFunctionResult.h
@@ -40,10 +40,9 @@ class WrapperFunctionResult {
}
WrapperFunctionResult &operator=(WrapperFunctionResult &&Other) {
- orc_rt_WrapperFunctionResult Tmp;
- orc_rt_WrapperFunctionResultInit(&Tmp);
- std::swap(Tmp, Other.R);
- std::swap(R, Tmp);
+ orc_rt_DisposeWrapperFunctionResult(&R);
+ orc_rt_WrapperFunctionResultInit(&R);
+ std::swap(R, Other.R);
return *this;
}
More information about the llvm-commits
mailing list