hare

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

commit e6b95a90c0c9c863a40b2d6201d18a99d79600cf
parent 7b41e12c2f47c56d99b7b5329ebb5224de6c16ab
Author: Mykyta Holubakha <hilobakho@gmail.com>
Date:   Wed, 29 May 2024 19:16:28 +0300

std: fix some low-hanging memory leaks

Diffstat:
Mnet/uri/parse.ha | 4++++
Mregex/regex.ha | 2++
Mtime/chrono/timescale.ha | 7+++++++
Mtime/date/virtual.ha | 1+
4 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/net/uri/parse.ha b/net/uri/parse.ha @@ -91,6 +91,7 @@ export fn parse(in: str) (uri | invalid) = { case let s: str => yield match (ip::parse(s)) { case let a: ip::addr => + free(s); yield a; case ip::invalid => yield s; @@ -160,6 +161,7 @@ fn parse_authority( }; const addr = percent_decode(memio::string(&buf)!)?; + defer free(addr); match (ip::parse(addr)) { case let v6: ip::addr6 => host = v6; @@ -334,6 +336,7 @@ fn percent_decode_static(out: io::handle, s: str) (void | invalid) = { return invalid; }; + free(percent_data); percent_data = []; }; @@ -348,6 +351,7 @@ fn percent_decode_static(out: io::handle, s: str) (void | invalid) = { return invalid; }; + free(percent_data); percent_data = []; }; diff --git a/regex/regex.ha b/regex/regex.ha @@ -922,6 +922,7 @@ fn parse_replace_target(targetstr: str) ([]([]u8 | size) | error) = { const r = match (strings::next(&iter)) { case done => + free(target); return "Trailing backslash": error; case let r: rune => yield r; @@ -932,6 +933,7 @@ fn parse_replace_target(targetstr: str) ([]([]u8 | size) | error) = { } else if (ascii::isdigit(r)) { append(target, r: u32: size - 0x30); } else { + free(target); return "Backslash must be followed by positive decimal number or a backslash": error; }; diff --git a/time/chrono/timescale.ha b/time/chrono/timescale.ha @@ -553,6 +553,10 @@ fn mtc_convfrom(ts: *timescale, i: time::instant) ([]time::instant | void) = { }, )); }; + if (actual is []time::instant) { + free(actual as []time::instant); + }; + }; }; @@ -648,5 +652,8 @@ fn mtc_convfrom(ts: *timescale, i: time::instant) ([]time::instant | void) = { }, )); }; + if (actual is []time::instant) { + free(actual as []time::instant); + }; }; }; diff --git a/time/date/virtual.ha b/time/date/virtual.ha @@ -272,6 +272,7 @@ export fn realize( return realize_validzoff(v, locs...); case let zf: zflag => let valid_dates = realize_validzoffs(v, locs...)?; + defer free(valid_dates); switch (len(valid_dates)) { case 0 => if (0 != zf & zflag::GAP_END) {