Fixed some deallocation code

This commit is contained in:
Alexandros Naskos 2020-07-02 14:44:12 +03:00
parent e54a6d2522
commit 21e18a1d01
2 changed files with 15 additions and 5 deletions

View File

@ -636,6 +636,7 @@ pub fn deinit(self: *DocumentStore) void {
var entry_iterator = self.handles.iterator();
while (entry_iterator.next()) |entry| {
entry.value.document_scope.deinit(self.allocator);
entry.value.tree.deinit();
self.allocator.free(entry.value.document.mem);
for (entry.value.import_uris.items) |uri| {
@ -662,6 +663,7 @@ pub fn deinit(self: *DocumentStore) void {
self.allocator.free(std_uri);
}
self.allocator.free(self.build_runner_path);
self.build_files.deinit(self.allocator);
self.error_completions.deinit();
self.enum_completions.deinit();

View File

@ -1374,15 +1374,14 @@ pub fn main() anyerror!void {
allocator = std.heap.page_allocator;
if (build_options.allocation_info) {
// TODO: Use a better debugging allocator, track size in bytes, memory reserved etc..
// Initialize the leak counting allocator.
debug_alloc_state = DebugAllocator.init(allocator, build_options.max_bytes_allocated);
allocator = &debug_alloc_state.allocator;
}
defer if (debug_alloc) |dbg| {
std.log.debug(.main, "Finished cleanup, last allocation info.\n", .{});
std.log.debug(.main, "{}\n", .{dbg.info});
std.debug.print("Finished cleanup, last allocation info.\n", .{});
std.debug.print("\n{}\n", .{dbg.info});
};
// Init global vars
@ -1490,7 +1489,16 @@ pub fn main() anyerror!void {
defer document_store.deinit();
workspace_folder_configs = std.StringHashMap(?Config).init(allocator);
defer workspace_folder_configs.deinit();
defer {
var it = workspace_folder_configs.iterator();
while (it.next()) |entry| {
allocator.free(entry.key);
if (entry.value) |c| {
std.json.parseFree(Config, c, std.json.ParseOptions{ .allocator = allocator });
}
}
workspace_folder_configs.deinit();
}
// This JSON parser is passed to processJsonRpc and reset.
var json_parser = std.json.Parser.init(allocator, false);
@ -1514,7 +1522,7 @@ pub fn main() anyerror!void {
arena.state.buffer_list = .{};
if (debug_alloc) |dbg| {
std.log.debug(.main, "{}\n", .{dbg.info});
std.log.debug(.main, "\n{}\n", .{dbg.info});
}
}
}