Fix not freeing a zero length String

This commit is contained in:
Christoffer Lerno
2025-01-05 14:29:55 +01:00
parent 4f0716ab13
commit 67ff78f1ca
3 changed files with 8 additions and 7 deletions

View File

@@ -526,6 +526,11 @@ fn String String.tconcat(s1, String s2) => s1.concat(s2, allocator::temp());
fn ZString String.zstr_tcopy(s) => s.zstr_copy(allocator::temp()) @inline;
<*
Copy this string, by duplicating the string, always adding a zero byte
sentinel, so that it safely can be converted to a ZString by a
cast.
*>
fn String String.copy(s, Allocator allocator = allocator::heap())
{
usz len = s.len;
@@ -537,7 +542,7 @@ fn String String.copy(s, Allocator allocator = allocator::heap())
fn void String.free(&s, Allocator allocator = allocator::heap())
{
if (!s.len) return;
if (!s.ptr) return;
allocator::free(allocator, s.ptr);
*s = "";
}