authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-31 17:33:04 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-31 17:33:04 -07:00
logb81a9ced5fceadce93207c59434e5905de3efba8
treebecfad7ecbe872147223ab15ecd8b7be07385279
parent7306ea63fbf1d83b3ba8df1822a55d2e859997ab
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

fix a memory leak on error


3 files changed, 39 insertions(+), 0 deletions(-)

fuzz/crashes/id:000000,sig:06,src:000000,time:2049,execs:911,op:quick,pos:263 created+31
......@@ -0,0 +1,31 @@
1id: g982zq6e8wsvnmduerpbf8787hu85brugmngn8wf
2name: yaml
3main: yaml.zig
4license: MIT
5description: A Yaml parser built on top of libyaml
6dependencies:
7 - src: git https://github.com/yaml/libyaml tag-0.2.5
8 id: 8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc
9 J license: MIT
10 c_include_dirs:
11 - include
12 c_source_flags:
13 - -DYAML_VERSION_MAJOR=0
14 - -DYAML_VERSION_MINOR=2
15 - -DYAML_VERSION_PATCH=5
16 - -DYAML_VERSION_STRING="0.2.5"
17 - -DYAML_DECLARE_STATIC=1
18 c_source_files:
19 - src/api.c
20 - src/dumper.c
21 - src/emitter.c
22 - src/loader.c
23 - src/parser.c
24 - src/reader.c
25 - src/scanner.c
26 - src/writer.c
27
28 - src: git https://github.com/nektro/zig-extras
29
30root_dependencies:
31 - src: git https://github.com/nektro/zig-expect
test.zig+5
......@@ -11,6 +11,11 @@ test {
1111
1212 try expect(doc.mapping.get_string("id").?).toEqualString("g982zq6e8wsvnmduerpbf8787hu85brugmngn8wf");
1313}
14test {
15 const alloc = std.testing.allocator;
16 const doc = yaml.parse(alloc, @embedFile("./fuzz/crashes/id:000000,sig:06,src:000000,time:2049,execs:911,op:quick,pos:263")) catch return;
17 defer doc.deinit(alloc);
18}
1419
1520fn parseTest(comptime basename: [:0]const u8) !void {
1621 const alloc = std.testing.allocator;
yaml.zig+3
......@@ -302,6 +302,7 @@ fn parse_document(p: *Parser) Error!Document {
302302 switch (tok.type) {
303303 c.YAML_MAPPING_START_EVENT => {
304304 const item = try parse_item(p, tok);
305 errdefer item.deinit(p.alloc);
305306 const tok2 = try p.next();
306307 if (tok2.type != c.YAML_DOCUMENT_END_EVENT) {
307308 return error.YamlUnexpectedToken;
......@@ -310,6 +311,7 @@ fn parse_document(p: *Parser) Error!Document {
310311 },
311312 c.YAML_SEQUENCE_START_EVENT => {
312313 const item = try parse_item(p, tok);
314 errdefer item.deinit(p.alloc);
313315 const tok2 = try p.next();
314316 if (tok2.type != c.YAML_DOCUMENT_END_EVENT) {
315317 return error.YamlUnexpectedToken;
......@@ -357,6 +359,7 @@ fn parse_value(p: *Parser) Error!Value {
357359fn parse_sequence(p: *Parser) Error!Sequence {
358360 var res = std.ArrayList(Item).init(p.alloc);
359361 errdefer res.deinit();
362 errdefer for (res.items) |k| k.deinit(p.alloc);
360363
361364 while (true) {
362365 const tok = try p.next();