Mem fixes

* `gpa.deinit()` now returns an enum
* avoid double free when `--config-path` is specified
* avoid leaking memory in `Server.create` if `configChanged` returns err
This commit is contained in:
nullptrdevs 2023-04-22 05:59:11 -07:00
parent 825cbd2e07
commit 5519b3a2c0
3 changed files with 4 additions and 3 deletions

View File

@ -7,7 +7,7 @@ const zls_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 };
pub fn build(b: *std.build.Builder) !void {
comptime {
const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse("0.11.0-dev.2571+31738de28") catch unreachable; // add c_char - https://github.com/ziglang/zig/pull/15263
const min_zig = std.SemanticVersion.parse("0.11.0-dev.2730+bd801dc48") catch unreachable; // gpa.deinit() now returns an enum
if (current_zig.order(min_zig) == .lt) {
@compileError(std.fmt.comptimePrint("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig }));
}

View File

@ -1549,6 +1549,7 @@ pub fn create(
message_tracing_enabled: bool,
) !*Server {
const server = try allocator.create(Server);
errdefer server.destroy();
server.* = Server{
.config = config,
.runtime_zig_version = null,

View File

@ -164,7 +164,7 @@ fn getConfig(
) !ConfigWithPath {
if (config_path) |path| {
if (configuration.loadFromFile(allocator, path)) |config| {
return ConfigWithPath{ .config = config, .config_path = path };
return ConfigWithPath{ .config = config, .config_path = try allocator.dupe(u8, path) };
}
std.debug.print(
\\Could not open configuration file '{s}'
@ -357,7 +357,7 @@ const stack_frames = switch (zig_builtin.mode) {
pub fn main() !void {
var gpa_state = std.heap.GeneralPurposeAllocator(.{ .stack_trace_frames = stack_frames }){};
defer std.debug.assert(!gpa_state.deinit());
defer std.debug.assert(gpa_state.deinit() == .ok);
var tracy_state = if (tracy.enable_allocation) tracy.tracyAllocator(gpa_state.allocator()) else void{};
const inner_allocator: std.mem.Allocator = if (tracy.enable_allocation) tracy_state.allocator() else gpa_state.allocator();