fix: alloc free off by one
parent
103e7abad5
commit
c5786c5d38
|
|
@ -353,6 +353,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
const char* ptr;
|
||||
uintptr_t len;
|
||||
uintptr_t cap;
|
||||
} ghostty_string_s;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,8 @@ export fn ghostty_config_open_path() c.String {
|
|||
return .empty;
|
||||
};
|
||||
|
||||
return .fromSlice(path);
|
||||
// Capacity is len + 1 due to sentinel
|
||||
return .fromSlice(path, path.len + 1);
|
||||
}
|
||||
|
||||
/// Sync with ghostty_diagnostic_s
|
||||
|
|
|
|||
|
|
@ -63,16 +63,19 @@ const Info = extern struct {
|
|||
pub const String = extern struct {
|
||||
ptr: ?[*]const u8,
|
||||
len: usize,
|
||||
cap: usize,
|
||||
|
||||
pub const empty: String = .{
|
||||
.ptr = null,
|
||||
.len = 0,
|
||||
.cap = 0,
|
||||
};
|
||||
|
||||
pub fn fromSlice(slice: []const u8) String {
|
||||
pub fn fromSlice(slice: []const u8, cap: usize) String {
|
||||
return .{
|
||||
.ptr = slice.ptr,
|
||||
.len = slice.len,
|
||||
.cap = cap,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
@ -129,5 +132,5 @@ pub export fn ghostty_translate(msgid: [*:0]const u8) [*:0]const u8 {
|
|||
|
||||
/// Free a string allocated by Ghostty.
|
||||
pub export fn ghostty_string_free(str: String) void {
|
||||
state.alloc.free(str.ptr.?[0..str.len]);
|
||||
state.alloc.free(str.ptr.?[0..str.cap]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue