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.
This commit is contained in:
Daniel A.C. Martin 2023-11-26 16:32:36 +00:00 committed by Andrew Kelley
parent f29302f915
commit 280140595f

View File

@ -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;