Skip to content

Commit

Permalink
Add deinit
Browse files Browse the repository at this point in the history
  • Loading branch information
g41797 committed Dec 31, 2024
1 parent 6e08d90 commit 7d1332b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/client_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test "put-state-reserve-delete" {

var job: Job = .{};
try job.init(std.testing.allocator);
defer job.free();
defer job.deinit();

try cl.reserve(0, &job);
const rid = job.id().?;
Expand Down Expand Up @@ -91,7 +91,7 @@ test "all-staff" {

var job: Job = .{};
try job.init(std.testing.allocator);
defer job.free();
defer job.deinit();

try cl.reserve(0, &job);
const rid = job.id().?;
Expand Down
9 changes: 8 additions & 1 deletion src/job.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub const Job = struct {
}

pub fn alloc(job: *Job, len: usize) !void {
if (!job.ready) {
return error.NotInitialized;
}
if (job.buffer == null) {
job.len = roundlen(len);
job.buffer = try job.allocator.alloc(u8, job.len);
Expand All @@ -66,7 +69,11 @@ pub const Job = struct {
return job.alloc(rlen);
}

pub fn free(job: *Job) void {
pub fn deinit(job: *Job) void {
job.free();
}

fn free(job: *Job) void {
if (job.buffer != null) {
job.allocator.free(job.buffer.?);
job.buffer = null;
Expand Down

0 comments on commit 7d1332b

Please sign in to comment.