[llvm] 23c1822 - [examples] Fix leaks in OrcV2 c-bindings examples.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 23 21:11:53 PST 2022
Author: Lang Hames
Date: 2022-12-23T21:11:47-08:00
New Revision: 23c1822d1a741cef2f1593f0e745cb74bbb3dbb0
URL: https://github.com/llvm/llvm-project/commit/23c1822d1a741cef2f1593f0e745cb74bbb3dbb0
DIFF: https://github.com/llvm/llvm-project/commit/23c1822d1a741cef2f1593f0e745cb74bbb3dbb0.diff
LOG: [examples] Fix leaks in OrcV2 c-bindings examples.
rdar://103599609
Added:
Modified:
llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/OrcV2CBindingsAddObjectFile.c
llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
llvm/examples/OrcV2Examples/OrcV2CBindingsReflectProcessSymbols/OrcV2CBindingsReflectProcessSymbols.c
llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/OrcV2CBindingsRemovableCode.c
Removed:
################################################################################
diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/OrcV2CBindingsAddObjectFile.c b/llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/OrcV2CBindingsAddObjectFile.c
index fca3c7522b85b..6735e35c4b9b1 100644
--- a/llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/OrcV2CBindingsAddObjectFile.c
+++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/OrcV2CBindingsAddObjectFile.c
@@ -50,6 +50,9 @@ LLVMModuleRef createDemoModule(LLVMContextRef Ctx) {
// - Build the return instruction.
LLVMBuildRet(Builder, Result);
+ // - Free the builder.
+ LLVMDisposeBuilder(Builder);
+
return M;
}
@@ -107,6 +110,12 @@ int main(int argc, char *argv[]) {
LLVMContextDispose(Ctx);
goto jit_cleanup;
}
+
+ // CodeGen succeeded -- We have our module, so free the Module, LLVMContext,
+ // and TargetMachine.
+ LLVMDisposeModule(M);
+ LLVMContextDispose(Ctx);
+ LLVMDisposeTargetMachine(TM);
}
// Add our object file buffer to the JIT.
diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c b/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
index 0c4196ffbd72d..412128b037d2e 100644
--- a/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
+++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
@@ -55,6 +55,9 @@ LLVMOrcThreadSafeModuleRef createDemoModule(void) {
// - Build the return instruction.
LLVMBuildRet(Builder, Result);
+ // - Free the builder.
+ LLVMDisposeBuilder(Builder);
+
// Our demo module is now complete. Wrap it and our ThreadSafeContext in a
// ThreadSafeModule.
LLVMOrcThreadSafeModuleRef TSM = LLVMOrcCreateNewThreadSafeModule(M, TSCtx);
diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsReflectProcessSymbols/OrcV2CBindingsReflectProcessSymbols.c b/llvm/examples/OrcV2Examples/OrcV2CBindingsReflectProcessSymbols/OrcV2CBindingsReflectProcessSymbols.c
index 0ce454dc431da..1891a13b7b3ae 100644
--- a/llvm/examples/OrcV2Examples/OrcV2CBindingsReflectProcessSymbols/OrcV2CBindingsReflectProcessSymbols.c
+++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsReflectProcessSymbols/OrcV2CBindingsReflectProcessSymbols.c
@@ -100,6 +100,9 @@ LLVMOrcThreadSafeModuleRef createDemoModule(void) {
// - Build the return instruction.
LLVMBuildRet(Builder, AddResult);
+ // - Free the builder.
+ LLVMDisposeBuilder(Builder);
+
// Our demo module is now complete. Wrap it and our ThreadSafeContext in a
// ThreadSafeModule.
LLVMOrcThreadSafeModuleRef TSM = LLVMOrcCreateNewThreadSafeModule(M, TSCtx);
diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/OrcV2CBindingsRemovableCode.c b/llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/OrcV2CBindingsRemovableCode.c
index 08567071dad8a..c826b299368f4 100644
--- a/llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/OrcV2CBindingsRemovableCode.c
+++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/OrcV2CBindingsRemovableCode.c
@@ -55,6 +55,9 @@ LLVMOrcThreadSafeModuleRef createDemoModule(void) {
// - Build the return instruction.
LLVMBuildRet(Builder, Result);
+ // - Free the builder.
+ LLVMDisposeBuilder(Builder);
+
// Our demo module is now complete. Wrap it and our ThreadSafeContext in a
// ThreadSafeModule.
LLVMOrcThreadSafeModuleRef TSM = LLVMOrcCreateNewThreadSafeModule(M, TSCtx);
More information about the llvm-commits
mailing list