Skip to content

Commit 4ac3bfe

Browse files
committed
move allocator logic in loop function for better stability in AFL
1 parent a06b265 commit 4ac3bfe

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/fuzz/afl.zig

+7-11
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,16 @@ const mem = std.mem;
1111
// std.debug.assert(toggle_me == false);
1212
// }
1313

14-
var gpa_impl: std.heap.GeneralPurposeAllocator(.{}) = .{};
15-
var arena_impl: std.heap.ArenaAllocator = .{
16-
.child_allocator = undefined,
17-
.state = .{},
18-
};
19-
20-
export fn zig_fuzz_init() void {
21-
const gpa = gpa_impl.allocator();
22-
arena_impl.child_allocator = gpa;
23-
}
14+
export fn zig_fuzz_init() void {}
2415

2516
export fn zig_fuzz_test(buf: [*]u8, len: isize) void {
17+
var gpa_impl: std.heap.GeneralPurposeAllocator(.{}) = .{};
18+
defer std.debug.assert(gpa_impl.deinit() == .ok);
19+
20+
var arena_impl = std.heap.ArenaAllocator.init(gpa_impl.allocator());
21+
defer arena_impl.deinit();
22+
2623
const arena = arena_impl.allocator();
27-
_ = arena_impl.reset(.retain_capacity);
2824

2925
const src = buf[0..@intCast(len)];
3026
var t = ctx;

0 commit comments

Comments
 (0)