hare

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

commit 9553e81ea9478e7081a2b0470a8a07aac4618cbb
parent db3a364664ba1652b4b0713408b80c93ad877830
Author: Sebastian <sebastian@sebsite.pw>
Date:   Tue, 17 Oct 2023 22:30:36 -0400

haredoc: fix memory leak

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mcmd/haredoc/doc/types.ha | 24++++++++++++++++++++++++
Mcmd/haredoc/main.ha | 4+++-
2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/cmd/haredoc/doc/types.ha b/cmd/haredoc/doc/types.ha @@ -63,3 +63,27 @@ export type summary = struct { globals: []ast::decl, funcs: []ast::decl, }; + +export fn finish_summary(s: summary) void = { + for (let i = 0z; i < len(s.constants); i += 1) { + free(s.constants[i].decl as []ast::decl_const); + }; + free(s.constants); + + for (let i = 0z; i < len(s.errors); i += 1) { + free(s.errors[i].decl as []ast::decl_type); + }; + free(s.errors); + + for (let i = 0z; i < len(s.types); i += 1) { + free(s.types[i].decl as []ast::decl_type); + }; + free(s.types); + + for (let i = 0z; i < len(s.globals); i += 1) { + free(s.globals[i].decl as []ast::decl_global); + }; + free(s.globals); + + free(s.funcs); +}; diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -216,6 +216,8 @@ fn doc(name: str, cmd: *getopt::command) (void | error) = { }; } else []; const srcs = if (!ambiguous && modpath != "") modsrcs else declsrcs; + const summary = doc::sort_decls(decls); + defer doc::finish_summary(summary); const ctx = doc::context { mctx = &ctx, ident = id, @@ -223,7 +225,7 @@ fn doc(name: str, cmd: *getopt::command) (void | error) = { ambiguous = ambiguous, srcs = srcs, submods = submods, - summary = doc::sort_decls(decls), + summary = summary, template = template, readme = readme, show_undocumented = show_undocumented,