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.
This commit is contained in:
Mitchell Hashimoto 2023-08-02 15:51:58 -07:00 committed by Andrew Kelley
parent 89d660c3eb
commit 76f7b40e15

View File

@ -1072,17 +1072,20 @@ pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void {
} }
pub fn addLibraryPath(self: *Compile, directory_source: LazyPath) 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); directory_source.addStepDependencies(&self.step);
} }
pub fn addRPath(self: *Compile, directory_source: LazyPath) void { 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); directory_source.addStepDependencies(&self.step);
} }
pub fn addFrameworkPath(self: *Compile, directory_source: LazyPath) void { 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); directory_source.addStepDependencies(&self.step);
} }