hare

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

commit eac36b91505385a02601362e029713a48d09ac9c
parent 0dbc18b1073aada9250a896baf921572ed326979
Author: Martin Quinson <martin.quinson@ens-rennes.fr>
Date:   Sun, 11 Feb 2024 00:59:42 +0100

Fix 102 memleaks in the stdlib tests

992 memleaks remain, but I prefer to break this change in parts to
ease the reviewing work.

Signed-off-by: Martin Quinson <martin.quinson@ens-rennes.fr>

Diffstat:
Mcmd/haredoc/main.ha | 5+++++
Mcrypto/aes/+test/gcm.ha | 3+++
Mcrypto/bcrypt/+test.ha | 2++
Mcrypto/bigint/+test/arithm_test.ha | 2++
Mcrypto/bigint/+test/encoding_test.ha | 1+
Mcrypto/curve25519/+test.ha | 1+
Mcrypto/sha1/+test.ha | 1+
Mcrypto/sha256/+test.ha | 1+
Mcrypto/sha512/+test.ha | 4++++
Mencoding/asn1/+test/decoder_test.ha | 1+
Mencoding/asn1/+test/encoder_test.ha | 2++
Mencoding/pem/+test.ha | 4++++
12 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -384,12 +384,17 @@ fn has_decl(decl: ast::decl, name: str) bool = { @test fn parseident() void = { let (ident, trailing) = parseident("hare::lex") as (ast::ident, bool); + defer ast::ident_free(ident); assert(ast::ident_eq(ident, ["hare", "lex"])); assert(!trailing); + let (ident, trailing) = parseident("rt::abort") as (ast::ident, bool); + defer ast::ident_free(ident); assert(ast::ident_eq(ident, ["rt", "abort"])); assert(!trailing); + let (ident, trailing) = parseident("foo::bar::") as (ast::ident, bool); + defer ast::ident_free(ident); assert(ast::ident_eq(ident, ["foo", "bar"])); assert(trailing); assert(parseident("strings::dup*{}&@") is void); diff --git a/crypto/aes/+test/gcm.ha b/crypto/aes/+test/gcm.ha @@ -608,6 +608,7 @@ const gcmtestcases: []gcmtestcase = [ } else { yield alloc([0...], len(t.cipher)); }; + defer free(result); let resultbuf = memio::fixed(result); let gstream = cipher::gcm(); @@ -635,6 +636,7 @@ const gcmtestcases: []gcmtestcase = [ } else { yield alloc([0...], len(t.cipher)); }; + defer free(result); let cipherbuf = memio::fixed(t.cipher); let gstream = cipher::gcm(); @@ -671,6 +673,7 @@ const gcmtestcases: []gcmtestcase = [ r[..] = t.plain[..]; yield r; }; + defer free(result); let resultbuf = memio::fixed(result); let gstream = cipher::gcm(); diff --git a/crypto/bcrypt/+test.ha b/crypto/bcrypt/+test.ha @@ -7,6 +7,7 @@ use strings; @test fn bcrypt() void = { const pass = strings::toutf8("hare is cool"); const hash = generate(pass, DEFAULT_COST); + defer free(hash); assert(compare(hash, pass)!); const notpass = strings::toutf8("hare is lame"); assert(!compare(hash, notpass)!); @@ -18,5 +19,6 @@ use strings; const expect = "$2a$10$XajjQvNhvvRt5GSeFk1xFeyqRrsxkhBkUiQeg0dt.wU1qD4aFDcga"; const hash = strings::fromutf8(bcrypt(pass, salt, 10)!)!; + defer free(hash); assert(strings::hassuffix(expect, hash)); }; diff --git a/crypto/bigint/+test/arithm_test.ha b/crypto/bigint/+test/arithm_test.ha @@ -7,7 +7,9 @@ use bytes; let result: [4]u8 = [0...]; let bx = fromhex("002132a0"); + defer free(bx); let by = fromhex("00ff3201"); + defer free(by); let carry = add(bx, by, 0); diff --git a/crypto/bigint/+test/encoding_test.ha b/crypto/bigint/+test/encoding_test.ha @@ -51,6 +51,7 @@ use bytes; const input: [4]u8 = [0, 0, 0, 10]; let mod = fromhex("00190000"); + defer free(mod); let resultbuf: []word = alloc([0...], encodelen(input)); let result: [4]u8 = [0...]; diff --git a/crypto/curve25519/+test.ha b/crypto/curve25519/+test.ha @@ -97,6 +97,7 @@ use io; }; let hex = hex::encodestr(out[..]); + defer free(hex); const expectedhex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a"; if (hex != expectedhex) { fmt::errorfln("\ngot {}, want {}", hex, expectedhex)!; diff --git a/crypto/sha1/+test.ha b/crypto/sha1/+test.ha @@ -35,6 +35,7 @@ use test; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); + defer free(shahex); if (shahex != vector.1) { fmt::errorfln("Vector {}: {} != {}", i, shahex, vector.1)!; abort(); diff --git a/crypto/sha256/+test.ha b/crypto/sha256/+test.ha @@ -32,6 +32,7 @@ use test; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); + defer free(shahex); if (shahex != vector.1) { fmt::errorfln("Vector {}: {} != {}", i, shahex, vector.1)!; abort(); diff --git a/crypto/sha512/+test.ha b/crypto/sha512/+test.ha @@ -28,6 +28,7 @@ use strings; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); + defer free(shahex); if (shahex != vector.1) { fmt::errorfln("Vector {}: {} != {}", i, shahex, vector.1)!; abort(); @@ -52,6 +53,7 @@ use strings; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); + defer free(shahex); if (shahex != vector.1) { fmt::errorfln("Vector {}: {} != {}", i, shahex, vector.1)!; abort(); @@ -76,6 +78,7 @@ use strings; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); + defer free(shahex); if (shahex != vector.1) { fmt::errorfln("Vector {}: {} != {}", i, shahex, vector.1)!; abort(); @@ -101,6 +104,7 @@ use strings; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); + defer free(shahex); if (shahex != vector.1) { fmt::errorfln("Vector {}: {} != {}", i, shahex, vector.1)!; abort(); diff --git a/encoding/asn1/+test/decoder_test.ha b/encoding/asn1/+test/decoder_test.ha @@ -127,6 +127,7 @@ fn d(i: []u8) decoder = { open_seq(dc)!; let r = strreader(dc, utag::UTF8_STRING)!; let s = io::drain(&r)!; + defer free(s); assert(finish(dc) is invalid); }; diff --git a/encoding/asn1/+test/encoder_test.ha b/encoding/asn1/+test/encoder_test.ha @@ -14,6 +14,7 @@ use types; @test fn write_id() void = { let buf = memio::dynamic(); + defer io::close(&buf)!; let e = derencoder(&buf); write_fixedprim(&e, class::UNIVERSAL, 0x2aa, [0x00])!; @@ -27,6 +28,7 @@ use types; assert(h.tagid == 0x2aa); let buf = memio::dynamic(); + defer io::close(&buf)!; let e = derencoder(&buf); write_fixedprim(&e, class::UNIVERSAL, types::U32_MAX, [0x00])!; diff --git a/encoding/pem/+test.ha b/encoding/pem/+test.ha @@ -22,6 +22,7 @@ use strings; assert(len(buf) >= len(testcert_bin)); const data = io::drain(&stream.1)!; + defer free(data); assert(bytes::equal(data, testcert_bin)); assert(next(&dec) is io::EOF); @@ -38,11 +39,13 @@ use strings; const stream = next(&dec)! as (str, pemdecoder); assert(stream.0 == "CERTIFICATE"); const data = io::drain(&stream.1)!; + defer free(data); assert(bytes::equal(data, testcert_bin)); const stream = next(&dec)! as (str, pemdecoder); assert(stream.0 == "PRIVATE KEY"); const data = io::drain(&stream.1)!; + defer free(data); assert(bytes::equal(data, testprivkey_bin)); assert(next(&dec) is io::EOF); @@ -178,6 +181,7 @@ const testprivkey_bin: [_]u8 = [ assert(len(buf) >= len(testcert_bin)); const data = io::drain(&stream.1)!; + defer free(data); assert(bytes::equal(data, testcrlf_bin)); assert(next(&dec) is io::EOF);