diff options
Diffstat (limited to 'interp')
-rw-r--r-- | interp/interp.go | 8 | ||||
-rw-r--r-- | interp/interp_test.go | 2 |
2 files changed, 10 insertions, 0 deletions
diff --git a/interp/interp.go b/interp/interp.go index 58de4a3b6..87aadf37e 100644 --- a/interp/interp.go +++ b/interp/interp.go @@ -50,10 +50,17 @@ func newRunner(mod llvm.Module, debug bool) *runner { return &r } +// Dispose deallocates all alloated LLVM resources. +func (r *runner) dispose() { + r.targetData.Dispose() + r.targetData = llvm.TargetData{} +} + // Run evaluates runtime.initAll function as much as possible at compile time. // Set debug to true if it should print output while running. func Run(mod llvm.Module, debug bool) error { r := newRunner(mod, debug) + defer r.dispose() initAll := mod.NamedFunction("runtime.initAll") bb := initAll.EntryBasicBlock() @@ -196,6 +203,7 @@ func RunFunc(fn llvm.Value, debug bool) error { // Create and initialize *runner object. mod := fn.GlobalParent() r := newRunner(mod, debug) + defer r.dispose() initName := fn.Name() if !strings.HasSuffix(initName, ".init") { return errorAt(fn, "interp: unexpected function name (expected *.init)") diff --git a/interp/interp_test.go b/interp/interp_test.go index a1bea65ef..7b2bb6197 100644 --- a/interp/interp_test.go +++ b/interp/interp_test.go @@ -40,6 +40,7 @@ func TestInterp(t *testing.T) { func runTest(t *testing.T, pathPrefix string) { // Read the input IR. ctx := llvm.NewContext() + defer ctx.Dispose() buf, err := llvm.NewMemoryBufferFromFile(pathPrefix + ".ll") os.Stat(pathPrefix + ".ll") // make sure this file is tracked by `go test` caching if err != nil { @@ -49,6 +50,7 @@ func runTest(t *testing.T, pathPrefix string) { if err != nil { t.Fatalf("could not load module:\n%v", err) } + defer mod.Dispose() // Perform the transform. err = Run(mod, false) |