hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit c40a6c39e86d4f2da6a728e1f6de9ab290786938
parent c2f81855ffd18e84231b32a67aaf3d75efa01fd6
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 10 Mar 2021 11:41:23 -0500

Free more state on exit

Diffstat:
Mmain.ha | 15++++++++++++++-
Mplan.ha | 10+++++++++-
2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/main.ha b/main.ha @@ -18,7 +18,19 @@ export fn main() void = { workdir = temp::dir(), ... }; - defer os::rmdirall(plan.workdir); + defer { + os::rmdirall(plan.workdir); + free(plan.workdir); + + for (let i = 0z; i < len(plan.complete); i += 1) { + let task = plan.complete[i]; + task_free(task); + }; + + free(plan.scheduled); + free(plan.complete); + }; + let ctx = module::context_init([module::tag { name = os::machine(), mode = module::tag_mode::INCLUSIVE, @@ -27,6 +39,7 @@ export fn main() void = { name = "linux", mode = module::tag_mode::INCLUSIVE, }]); + //defer module::context_free(&ctx); // TODO const rtdir = match (module::lookup(&ctx, ["rt"])) { err: module::error => fmt::fatal("Error resolving rt: {}", diff --git a/plan.ha b/plan.ha @@ -3,6 +3,7 @@ use hare::module; use os::exec; use os; use path; +use strings; type status = enum { SCHEDULED, @@ -24,6 +25,13 @@ type plan = struct { script: str, }; +fn task_free(task: *task) void = { + free(task.depend); + free(task.output); + free(task.cmd); + free(task); +}; + // Schedules a task which compiles objects into an executable. fn sched_ld(plan: *plan, output: str, depend: *task...) *task = { let task = alloc(task { @@ -100,7 +108,7 @@ fn sched_hare_exe( let qbe = sched_qbe(plan, s, harec); let asm = sched_as(plan, o, qbe); - return sched_ld(plan, output, asm); + return sched_ld(plan, strings::dup(output), asm); }; fn execute(