Skip to content

Commit

Permalink
fix various memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Jan 6, 2025
1 parent f253553 commit a877dee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/DocumentStore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,14 @@ pub const Handle = struct {
var old_cimports = self.cimports;
var old_document_scope = if (old_status.has_document_scope) self.impl.document_scope else null;
var old_zir = if (old_status.has_zir) self.impl.zir else null;
var old_zoir = if (old_status.has_zoir) self.impl.zoir else null;

self.tree = new_tree;
self.import_uris = .empty;
self.cimports = .empty;
self.impl.document_scope = undefined;
self.impl.zir = undefined;
self.impl.zoir = undefined;

self.version += 1;

Expand All @@ -574,6 +576,7 @@ pub const Handle = struct {

if (old_document_scope) |*document_scope| document_scope.deinit(self.impl.allocator);
if (old_zir) |*zir| zir.deinit(self.impl.allocator);
if (old_zoir) |*zoir| zoir.deinit(self.impl.allocator);
}

fn deinit(self: *Handle) void {
Expand All @@ -585,6 +588,7 @@ pub const Handle = struct {
const allocator = self.impl.allocator;

if (status.has_zir) self.impl.zir.deinit(allocator);
if (status.has_zoir) self.impl.zoir.deinit(allocator);
if (status.has_document_scope) self.impl.document_scope.deinit(allocator);
allocator.free(self.tree.source);
self.tree.deinit(allocator);
Expand Down
2 changes: 2 additions & 0 deletions src/features/diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ pub const BuildOnSave = struct {
defer transport.deinit();

var diagnostic_tags: std.AutoArrayHashMapUnmanaged(DiagnosticsCollection.Tag, void) = .empty;
defer diagnostic_tags.deinit(self.allocator);

defer {
for (diagnostic_tags.keys()) |tag| collection.clearErrorBundle(tag);
collection.publishDiagnostics() catch {};
Expand Down
4 changes: 4 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ pub fn main() !u8 {
log_transport = if (result.disable_lsp_logs) null else transport.any();
log_stderr = result.enable_stderr_logs;
log_level = result.log_level orelse log_level;
defer {
log_transport = null;
log_stderr = true;
}

log.info("Starting ZLS {s} @ '{s}'", .{ zls.build_options.version_string, result.zls_exe_path });
log.info("Log File: {?s} ({s})", .{ log_file_path, @tagName(log_level) });
Expand Down

0 comments on commit a877dee

Please sign in to comment.