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 = "";
}

View File

@@ -55,6 +55,7 @@
- Assert on certain slice to slice casts. #1768.
- Fix vector float -> bool conversion.
- Fix `+a = 1` erronously being accepted.
- Fix not freeing a zero length String
### Stdlib changes
- Increase BitWriter.write_bits limit up to 32 bits.

View File

@@ -3083,7 +3083,6 @@ static void gencontext_emit_slice(GenContext *c, BEValue *be_value, Expr *expr)
llvm_value_rvalue(c, &start);
llvm_value_rvalue(c, &end);
// Calculate the size
LLVMValueRef size;
if (is_exclusive)
@@ -3268,11 +3267,7 @@ static void llvm_emit_slice_assign(GenContext *c, BEValue *be_value, Expr *expr)
llvm_emit_br(c, cond_block);
// Finally set up our phi
if (!assign_block_end)
{
offset = start.value;
}
else
if (assign_block_end)
{
llvm_set_phi(offset, start.value, start_block, next_offset, assign_block_end);
}