refactor(cli): use packet.deinit() in remaining command files
Replace manual defer blocks with packet.deinit() for consistent cleanup: - jupyter.zig: 5 locations updated (restoreJupyter, startJupyter, stopJupyter, removeJupyter, listServices, packageCommands) - experiment.zig: 3 locations updated (executeLog, executeShow, executeDelete) - queue.zig: 1 location updated (queueSingleJob) - logs.zig: 1 location updated (run) Eliminates 44 manual cleanup blocks across 4 files. Build verified: zig build --release=fast
This commit is contained in:
parent
29d130dcdb
commit
f2f645fe21
4 changed files with 11 additions and 75 deletions
|
|
@ -224,16 +224,7 @@ fn executeLog(allocator: std.mem.Allocator, args: []const []const u8, options: *
|
|||
);
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
if (packet.success_message) |msg| allocator.free(msg);
|
||||
if (packet.error_message) |msg| allocator.free(msg);
|
||||
if (packet.error_details) |details| allocator.free(details);
|
||||
if (packet.data_type) |dtype| allocator.free(dtype);
|
||||
if (packet.data_payload) |payload| allocator.free(payload);
|
||||
if (packet.progress_message) |pmsg| allocator.free(pmsg);
|
||||
if (packet.status_data) |sdata| allocator.free(sdata);
|
||||
if (packet.log_message) |lmsg| allocator.free(lmsg);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
switch (packet.packet_type) {
|
||||
.success => {
|
||||
|
|
@ -290,14 +281,7 @@ fn executeShow(allocator: std.mem.Allocator, args: []const []const u8, options:
|
|||
defer allocator.free(message);
|
||||
|
||||
const packet = try protocol.ResponsePacket.deserialize(message, allocator);
|
||||
defer {
|
||||
// Clean up allocated strings from packet
|
||||
if (packet.success_message) |msg| allocator.free(msg);
|
||||
if (packet.error_message) |msg| allocator.free(msg);
|
||||
if (packet.error_details) |details| allocator.free(details);
|
||||
if (packet.data_type) |dtype| allocator.free(dtype);
|
||||
if (packet.data_payload) |payload| allocator.free(payload);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
// For now, let's just print the result
|
||||
switch (packet.packet_type) {
|
||||
|
|
@ -533,16 +517,7 @@ fn executeDelete(allocator: std.mem.Allocator, identifier: []const u8, options:
|
|||
if (message.len > 0) {
|
||||
const packet = protocol.ResponsePacket.deserialize(message, allocator) catch null;
|
||||
if (packet) |p| {
|
||||
defer {
|
||||
if (p.success_message) |msg| allocator.free(msg);
|
||||
if (p.error_message) |msg| allocator.free(msg);
|
||||
if (p.error_details) |details| allocator.free(details);
|
||||
if (p.data_type) |dtype| allocator.free(dtype);
|
||||
if (p.data_payload) |payload| allocator.free(payload);
|
||||
if (p.progress_message) |pmsg| allocator.free(pmsg);
|
||||
if (p.status_data) |sdata| allocator.free(sdata);
|
||||
if (p.log_message) |lmsg| allocator.free(lmsg);
|
||||
}
|
||||
defer p.deinit(allocator);
|
||||
|
||||
switch (p.packet_type) {
|
||||
.success => {
|
||||
|
|
|
|||
|
|
@ -70,11 +70,7 @@ fn restoreJupyter(allocator: std.mem.Allocator, args: []const []const u8) !void
|
|||
colors.printError("Failed to parse response: {}\n", .{err});
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
if (packet.success_message) |msg| allocator.free(msg);
|
||||
if (packet.error_message) |msg| allocator.free(msg);
|
||||
if (packet.error_details) |details| allocator.free(details);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
switch (packet.packet_type) {
|
||||
.success => {
|
||||
|
|
@ -319,11 +315,7 @@ fn startJupyter(allocator: std.mem.Allocator, args: []const []const u8) !void {
|
|||
colors.printError("Failed to parse response: {}\n", .{err});
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
if (packet.success_message) |msg| allocator.free(msg);
|
||||
if (packet.error_message) |msg| allocator.free(msg);
|
||||
if (packet.error_details) |details| allocator.free(details);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
switch (packet.packet_type) {
|
||||
.success => {
|
||||
|
|
@ -400,11 +392,7 @@ fn stopJupyter(allocator: std.mem.Allocator, args: []const []const u8) !void {
|
|||
colors.printError("Failed to parse response: {}\n", .{err});
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
if (packet.success_message) |msg| allocator.free(msg);
|
||||
if (packet.error_message) |msg| allocator.free(msg);
|
||||
if (packet.error_details) |details| allocator.free(details);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
switch (packet.packet_type) {
|
||||
.success => {
|
||||
|
|
@ -519,11 +507,7 @@ fn removeJupyter(allocator: std.mem.Allocator, args: []const []const u8) !void {
|
|||
colors.printError("Failed to parse response: {}\n", .{err});
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
if (packet.success_message) |msg| allocator.free(msg);
|
||||
if (packet.error_message) |msg| allocator.free(msg);
|
||||
if (packet.error_details) |details| allocator.free(details);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
switch (packet.packet_type) {
|
||||
.success => {
|
||||
|
|
@ -595,12 +579,7 @@ fn listServices(allocator: std.mem.Allocator) !void {
|
|||
colors.printError("Failed to parse response: {}\n", .{err});
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
if (packet.data_type) |dtype| allocator.free(dtype);
|
||||
if (packet.data_payload) |payload| allocator.free(payload);
|
||||
if (packet.error_message) |msg| allocator.free(msg);
|
||||
if (packet.error_details) |details| allocator.free(details);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
switch (packet.packet_type) {
|
||||
.data => {
|
||||
|
|
@ -841,12 +820,7 @@ fn packageCommands(args: []const []const u8) !void {
|
|||
colors.printError("Failed to parse response: {}\n", .{err});
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
if (packet.data_type) |dtype| allocator.free(dtype);
|
||||
if (packet.data_payload) |payload| allocator.free(payload);
|
||||
if (packet.error_message) |msg| allocator.free(msg);
|
||||
if (packet.error_details) |details| allocator.free(details);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
switch (packet.packet_type) {
|
||||
.data => {
|
||||
|
|
|
|||
|
|
@ -72,13 +72,7 @@ pub fn run(allocator: std.mem.Allocator, argv: []const []const u8) !void {
|
|||
std.debug.print("{s}\n", .{message});
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
if (packet.success_message) |m| allocator.free(m);
|
||||
if (packet.error_message) |m| allocator.free(m);
|
||||
if (packet.error_details) |m| allocator.free(m);
|
||||
if (packet.data_payload) |m| allocator.free(m);
|
||||
if (packet.data_type) |m| allocator.free(m);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
switch (packet.packet_type) {
|
||||
.data => {
|
||||
|
|
|
|||
|
|
@ -488,14 +488,7 @@ fn queueSingleJob(
|
|||
}
|
||||
return;
|
||||
};
|
||||
defer {
|
||||
if (packet.success_message) |m| allocator.free(m);
|
||||
if (packet.error_message) |m| allocator.free(m);
|
||||
if (packet.error_details) |m| allocator.free(m);
|
||||
if (packet.data_payload) |m| allocator.free(m);
|
||||
if (packet.data_type) |m| allocator.free(m);
|
||||
if (packet.status_data) |m| allocator.free(m);
|
||||
}
|
||||
defer packet.deinit(allocator);
|
||||
|
||||
switch (packet.packet_type) {
|
||||
.success => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue