authorgravatar for github@daniel-martin.co.ukDaniel A.C. Martin <github@daniel-martin.co.uk> 2023-11-26 16:32:36+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-26 21:33:28-05:00
log280140595fcfe9676ed32a7906eb7958a4c595b1
tree8df25bbd8a24970749382cd2aaf4bc092e84c20c
parentf29302f9152a0c15641596c148a2d784991fe7d8

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 files changed, 1 insertions(+), 1 deletions(-)

lib/std/Build.zig+1-1
...@@ -869,7 +869,7 @@ pub fn createModule(b: *Build, options: CreateModuleOptions) *Module {...@@ -869,7 +869,7 @@ pub fn createModule(b: *Build, options: CreateModuleOptions) *Module {
869 const module = b.allocator.create(Module) catch @panic("OOM");869 const module = b.allocator.create(Module) catch @panic("OOM");
870 module.* = .{870 module.* = .{
871 .builder = b,871 .builder = b,
872 .source_file = options.source_file,872 .source_file = options.source_file.dupe(b),
873 .dependencies = moduleDependenciesToArrayHashMap(b.allocator, options.dependencies),873 .dependencies = moduleDependenciesToArrayHashMap(b.allocator, options.dependencies),
874 };874 };
875 return module;875 return module;