fix memory leak on error in makeInnerScope

This commit is contained in:
Techatrix 2023-05-29 23:47:39 +02:00
parent 8b941e5444
commit a6f7e80ea3

View File

@ -2693,18 +2693,18 @@ fn makeInnerScope(context: ScopeContext, tree: Ast, node_idx: Ast.Node.Index) er
if (container_decl.ast.enum_token != null) { if (container_decl.ast.enum_token != null) {
if (std.mem.eql(u8, name, "_")) return; if (std.mem.eql(u8, name, "_")) return;
const Documentation = @TypeOf(@as(types.CompletionItem, undefined).documentation);
var doc: Documentation = if (try getDocComments(allocator, tree, decl, .markdown)) |docs| .{ .MarkupContent = types.MarkupContent{ .kind = .markdown, .value = docs } } else null; const doc = try getDocComments(allocator, tree, decl, .markdown);
errdefer if (doc) |d| allocator.free(d);
var gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{ var gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{
.label = name, .label = name,
.kind = .Constant, .kind = .Constant,
.insertText = name, .insertText = name,
.insertTextFormat = .PlainText, .insertTextFormat = .PlainText,
.documentation = doc, .documentation = if (doc) |d| .{ .MarkupContent = types.MarkupContent{ .kind = .markdown, .value = d } } else null,
}); });
if (gop_res.found_existing) { if (gop_res.found_existing) {
if (doc) |d| allocator.free(d.MarkupContent.value); if (doc) |d| allocator.free(d);
} }
} }
} }