From 76f7b40e15456ed6ec2249607a91e8398a0d39e8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 2 Aug 2023 15:51:58 -0700 Subject: [PATCH] build: dupe library, rpath, and framework LazyPaths Without duping, users could get some unexpected behavior if they used a string with a lifetime that didn't persist throughout the full build, i.e. if it wasn't heap allocated, or if it was explicitly freed. --- lib/std/Build/Step/Compile.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 8d6744062f..b414d43e27 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -1072,17 +1072,20 @@ pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void { } pub fn addLibraryPath(self: *Compile, directory_source: LazyPath) void { - self.lib_paths.append(directory_source) catch @panic("OOM"); + const b = self.step.owner; + self.lib_paths.append(directory_source.dupe(b)) catch @panic("OOM"); directory_source.addStepDependencies(&self.step); } pub fn addRPath(self: *Compile, directory_source: LazyPath) void { - self.rpaths.append(directory_source) catch @panic("OOM"); + const b = self.step.owner; + self.rpaths.append(directory_source.dupe(b)) catch @panic("OOM"); directory_source.addStepDependencies(&self.step); } pub fn addFrameworkPath(self: *Compile, directory_source: LazyPath) void { - self.framework_dirs.append(directory_source) catch @panic("OOM"); + const b = self.step.owner; + self.framework_dirs.append(directory_source.dupe(b)) catch @panic("OOM"); directory_source.addStepDependencies(&self.step); }