Commit 280140595f

Daniel A.C. Martin <github@daniel-martin.co.uk>
2023-11-26 17:32:36
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.
1 parent f29302f
Changed files (1)
lib
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;