Skip to content

Commit

Permalink
Merge pull request #32 from Srekel/main
Browse files Browse the repository at this point in the history
Fixed crash due to accessing dealloced memory in class_info.
  • Loading branch information
lassade authored Oct 17, 2024
2 parents da79d27 + c9a3519 commit 6800262
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Transpiler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ fn visitCXXRecordDecl(self: *Self, value: *const json.Value) !void {
name = v.string;
} else if (self.scope.tag == .class) {
is_generated_name = true;
name = try fmt.allocPrint(self.allocator, "__{s}{d}", .{
// NOTE: Not certain this needs to survive forever but it's not much memory in the grand scope
// so using the global arena is fast and simple.
name = try fmt.allocPrint(self.arena.allocator(), "__{s}{d}", .{
if (is_union) "Union" else "Struct",
self.scope.fields,
});
Expand All @@ -570,7 +572,6 @@ fn visitCXXRecordDecl(self: *Self, value: *const json.Value) !void {
_ = try self.namespace.unnamed_nodes.put(id, value.*);
return;
}
defer if (is_generated_name) self.allocator.free(name);

const inner = value.object.getPtr("inner");
if (inner == null) {
Expand Down

0 comments on commit 6800262

Please sign in to comment.