Commit 76f7b40e15

Mitchell Hashimoto <mitchell.hashimoto@gmail.com>
2023-08-03 00:51:58
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.
1 parent 89d660c
Changed files (1)
lib
std
Build
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);
 }