Skip to content

Commit 214dbd6

Browse files
authored
Merge pull request #62 from thechampagne/master
c_api: fix memory leak
2 parents 9e8b883 + ef9c079 commit 214dbd6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/c_api.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export fn capy_button_new() ?CapyWidget {
7171
const button = allocator.create(capy.Button) catch return null;
7272
button.* = capy.button(.{});
7373

74-
const widget = allocator.create(capy.Widget) catch return null;
74+
const widget = allocator.create(capy.Widget) catch {
75+
allocator.destroy(button);
76+
return null;
77+
};
7578
widget.* = capy.internal.genericWidgetFrom(button) catch unreachable; // it can't error as the component doesn't have a widget and no allocation is necessary
7679
button.widget_data.atoms.widget = widget;
7780
return widget;

0 commit comments

Comments
 (0)