Skip to content

ondemand invalid free #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
travisstaloch opened this issue Mar 5, 2025 · 1 comment
Open

ondemand invalid free #25

travisstaloch opened this issue Mar 5, 2025 · 1 comment

Comments

@travisstaloch
Copy link
Owner

const simdjzon = @import("simdjzon");
const dom = simdjzon.dom;
const std = @import("std");
const testing = std.testing;
const allr = std.testing.allocator;
const ondemand = simdjzon.ondemand;

test "ondemand get with struct" {
    const S = struct { a: struct { b: []const u8 } };
    const input =
        \\{"a": {"b": "b-string"}}
    ;
    var src = std.io.StreamSource{ .const_buffer = std.io.fixedBufferStream(input) };
    var parser = try ondemand.Parser.init(&src, allr, "<fba>", .{});
    defer parser.deinit();
    var doc = try parser.iterate();

    var s: S = undefined;
    try doc.get(&s, .{ .allocator = allr });
    std.debug.print("s.a.b '{s}'\n", .{s.a.b});
    defer allr.free(s.a.b]);
    try testing.expectEqualStrings("b-string", s.a.b);
}
$ zig build test
test
└─ run test failure
thread 1154051 panic: Invalid free
~/Documents/Code/zig/zig/download/0.14.0/files/lib/std/heap/debug_allocator.zig:870:49: 0x1064377 in free (test)
            if (bucket.canary != config.canary) @panic("Invalid free");
                                                ^
~/Documents/Code/zig/zig/download/0.14.0/files/lib/std/mem/Allocator.zig:147:25: 0x108dffb in free__anon_11897 (test)
    return a.vtable.free(a.ptr, memory, alignment, ret_addr);
                        ^
/tmp/asdf2/src/main.zig:51:20: 0x110de8b in test.ondemand get with struct (test)
    defer allr.free(s.a.b);
                   ^
@travisstaloch
Copy link
Owner Author

I only noticed this today with zig 0.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant