Skip to content

Commit cd11ebd

Browse files
committed
Addressed memory issue
1 parent 8bbdfdf commit cd11ebd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

conformance/src/main.zig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ fn handleAttestationResultRoute(request: *httpz.Request, response: *httpz.Respon
623623
response.status = 400; // Bad Request
624624
response.content_type = httpz.ContentType.JSON;
625625
var json_output = std.ArrayList(u8).init(global_allocator);
626-
defer json_output.deinit();
626+
// defer json_output.deinit();
627627
try std.json.stringify(lib.ServerResponse.failure("Invalid JSON format"), .{}, json_output.writer());
628628
response.body = json_output.items;
629629
return;
@@ -683,7 +683,7 @@ fn handleAttestationResultRoute(request: *httpz.Request, response: *httpz.Respon
683683
response.status = 400; // Bad Request
684684
response.content_type = httpz.ContentType.JSON;
685685
var json_output = std.ArrayList(u8).init(global_allocator);
686-
defer json_output.deinit();
686+
// defer json_output.deinit();
687687
try std.json.stringify(lib.ServerResponse.failure(@errorName(err)), .{}, json_output.writer());
688688
response.body = json_output.items;
689689
return;
@@ -733,9 +733,11 @@ fn handleAttestationResultRoute(request: *httpz.Request, response: *httpz.Respon
733733
response.content_type = httpz.ContentType.JSON;
734734
response.status = 200; // Always OK for conformance test
735735
var json_output = std.ArrayList(u8).init(global_allocator);
736-
errdefer json_output.deinit();
736+
defer json_output.deinit();
737737
try std.json.stringify(lib.ServerResponse.success(), .{}, json_output.writer());
738-
response.body = json_output.items;
738+
739+
// Make sure we create a copy of the JSON data that will persist after the function returns
740+
response.body = try global_allocator.dupe(u8, json_output.items);
739741
}
740742

741743
// Route handler for assertion/options (authentication start)
@@ -943,7 +945,9 @@ fn handleAssertionResultRoute(request: *httpz.Request, response: *httpz.Response
943945
var json_output = std.ArrayList(u8).init(global_allocator);
944946
defer json_output.deinit();
945947
try std.json.stringify(lib.ServerResponse.success(), .{}, json_output.writer());
946-
response.body = json_output.items;
948+
949+
// Make sure we create a copy of the JSON data that will persist after the function returns
950+
response.body = try global_allocator.dupe(u8, json_output.items);
947951
}
948952

949953
// Core implementation functions

0 commit comments

Comments
 (0)