Selaa lähdekoodia

Attempt to free stdout memory

Luna Stadler 4 vuotta sitten
vanhempi
commit
a906808ef7
1 muutettua tiedostoa jossa 4 lisäystä ja 1 poistoa
  1. 4 1
      zig/sdl/hello_sdl.zig

+ 4 - 1
zig/sdl/hello_sdl.zig

@ -64,7 +64,7 @@ pub fn main() !void {
64 64
    var pos: usize = 0;
65 65
    var max_chars = std.math.min(@divTrunc(@intCast(usize, window_width), @intCast(usize, glyph_width)), msg.len);
66 66
67
    var result: []const u8 = "";
67
    var result: []const u8 = try gpa.alloc(u8, 0);
68 68
69 69
    const keyboardState = c.SDL_GetKeyboardState(null);
70 70
@ -115,6 +115,7 @@ pub fn main() !void {
115 115
                                msg[pos] = '_';
116 116
                            },
117 117
                            c.SDLK_RETURN => {
118
                                gpa.free(result);
118 119
                                result = try runCommand(&msg, gpa);
119 120
                                var i: usize = 0;
120 121
                                while (i < max_chars) : (i += 1) {
@ -170,6 +171,8 @@ pub fn main() !void {
170 171
171 172
        c.SDL_Delay(16);
172 173
    }
174
175
    _ = general_purpose_allocator.detectLeaks();
173 176
}
174 177
175 178
fn runCommand(raw_cmd: []const u8, allocator: *std.mem.Allocator) ![]const u8 {