From 280140595fcfe9676ed32a7906eb7958a4c595b1 Mon Sep 17 00:00:00 2001 From: "Daniel A.C. Martin" Date: Sun, 26 Nov 2023 16:32:36 +0000 Subject: [PATCH] fix: Prevent segfault when using add.Module() This duplicates the source file string (as is done in other places such as `addAssemblyFile()`) in order to prevent a segfault when the supplied string is freed by the caller. This is still seen when the caller makes use of a defer statement. --- lib/std/Build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 9b1677c40f..7ace959473 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -869,7 +869,7 @@ pub fn createModule(b: *Build, options: CreateModuleOptions) *Module { const module = b.allocator.create(Module) catch @panic("OOM"); module.* = .{ .builder = b, - .source_file = options.source_file, + .source_file = options.source_file.dupe(b), .dependencies = moduleDependenciesToArrayHashMap(b.allocator, options.dependencies), }; return module;