authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-11-16 21:22:43-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-11-16 21:29:17-05:00
log5be8a5fe5f25064ce963fa7a38942e387254de8d
tree7ffdabbcd87861a8cc0f646120d0b59b54cd1a96
parenta8ec306b493ddac701f279bfe82808525956f3f2

link: fix memory bugs


2 files changed, 5 insertions(+), 2 deletions(-)

src/link/Elf/SharedObject.zig+1
...@@ -72,6 +72,7 @@ pub const Parsed = struct {...@@ -72,6 +72,7 @@ pub const Parsed = struct {
7272
73 pub fn deinit(p: *Parsed, gpa: Allocator) void {73 pub fn deinit(p: *Parsed, gpa: Allocator) void {
74 gpa.free(p.strtab);74 gpa.free(p.strtab);
75 gpa.free(p.sections);
75 gpa.free(p.symtab);76 gpa.free(p.symtab);
76 gpa.free(p.versyms);77 gpa.free(p.versyms);
77 gpa.free(p.symbols);78 gpa.free(p.symbols);
src/main.zig+4-2
...@@ -984,6 +984,7 @@ fn buildOutputType(...@@ -984,6 +984,7 @@ fn buildOutputType(
984 .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena),984 .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena),
985 .native_system_include_paths = &.{},985 .native_system_include_paths = &.{},
986 };986 };
987 defer create_module.link_inputs.deinit(gpa);
987988
988 // before arg parsing, check for the NO_COLOR and CLICOLOR_FORCE environment variables989 // before arg parsing, check for the NO_COLOR and CLICOLOR_FORCE environment variables
989 // if set, default the color setting to .off or .on, respectively990 // if set, default the color setting to .off or .on, respectively
...@@ -3682,7 +3683,7 @@ const CreateModule = struct {...@@ -3682,7 +3683,7 @@ const CreateModule = struct {
3682 /// This one is used while collecting CLI options. The set of libs is used3683 /// This one is used while collecting CLI options. The set of libs is used
3683 /// directly after computing the target and used to compute link_libc,3684 /// directly after computing the target and used to compute link_libc,
3684 /// link_libcpp, and then the libraries are filtered into3685 /// link_libcpp, and then the libraries are filtered into
3685 /// `unresolved_linker_inputs` and `windows_libs`.3686 /// `unresolved_link_inputs` and `windows_libs`.
3686 cli_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput),3687 cli_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput),
3687 windows_libs: std.StringArrayHashMapUnmanaged(void),3688 windows_libs: std.StringArrayHashMapUnmanaged(void),
3688 /// The local variable `unresolved_link_inputs` is fed into library3689 /// The local variable `unresolved_link_inputs` is fed into library
...@@ -3816,7 +3817,8 @@ fn createModule(...@@ -3816,7 +3817,8 @@ fn createModule(
3816 // to decide whether to trigger native path detection logic.3817 // to decide whether to trigger native path detection logic.
3817 // Preserves linker input order.3818 // Preserves linker input order.
3818 var unresolved_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput) = .empty;3819 var unresolved_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput) = .empty;
3819 try unresolved_link_inputs.ensureUnusedCapacity(arena, create_module.cli_link_inputs.items.len);3820 defer unresolved_link_inputs.deinit(gpa);
3821 try unresolved_link_inputs.ensureUnusedCapacity(gpa, create_module.cli_link_inputs.items.len);
3820 var any_name_queries_remaining = false;3822 var any_name_queries_remaining = false;
3821 for (create_module.cli_link_inputs.items) |cli_link_input| switch (cli_link_input) {3823 for (create_module.cli_link_inputs.items) |cli_link_input| switch (cli_link_input) {
3822 .name_query => |nq| {3824 .name_query => |nq| {