[examples] Fix leaks in OrcV2 c-bindings examples.

rdar://103599609
This commit is contained in:
Lang Hames 2022-12-23 21:01:09 -08:00
parent 073cc29e04
commit 23c1822d1a
4 changed files with 18 additions and 0 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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);

View File

@ -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);