zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 280140595fcfe9676ed32a7906eb7958a4c595b1 (tree)
parent f29302f9152a0c15641596c148a2d784991fe7d8
Author: Daniel A.C. Martin <github@daniel-martin.co.uk>
Date:   Sun, 26 Nov 2023 16:32:36 +0000

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.

Diffstat:
Mlib/std/Build.zig | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 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;