Skip to content

Commit

Permalink
free category (#68)
Browse files Browse the repository at this point in the history
* free category

* fix ctx
  • Loading branch information
jiacai2050 committed Jul 17, 2023
1 parent ce4175e commit adb15c7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
12 changes: 12 additions & 0 deletions core/omg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1566,3 +1566,15 @@ void omg_free_discussion(omg_discussion *discussion) {
}
}
}

void omg_free_repo_discussion_category(omg_repo_discussion_category *category) {
if (category != NULL) {
free(category->id);
for (size_t i = 0; i < category->len; i++) {
free(category->categories[i].id);
free(category->categories[i].name);
}

free(category->categories);
}
}
6 changes: 6 additions & 0 deletions core/omg.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ typedef struct {
size_t len;
} omg_repo_discussion_category;

void omg_free_repo_discussion_category(omg_repo_discussion_category *);

#define omg_auto_repo_discussion_category \
omg_repo_discussion_category \
__attribute__((cleanup(omg_free_repo_discussion_category)))

omg_error omg_query_repo_discussion_category(omg_context, const char *owner,
const char *name,
omg_repo_discussion_category *);
Expand Down
2 changes: 1 addition & 1 deletion tests/core.zig
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn test_create_pull(ctx: ?*clib.struct_omg_context) anyerror!void {
}

fn test_star_repo(ctx: ?*clib.struct_omg_context) anyerror!void {
try check_error(clib.omg_star_repo(ctx, "jiacai2050/oh-my-github"));
try check_error(clib.omg_star_repo(ctx, "xigua2023/xigua2023"));
}

pub fn main() anyerror!void {
Expand Down
5 changes: 3 additions & 2 deletions tests/discussion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const testing = std.testing;
const time = std.time;

pub fn main() !void {
const ctx = try util.init_ctx();
var ctx = try util.init_ctx();
defer c.omg_free_context(&ctx);

// https://github.com/xigua2023/test-github-api/discussions
try create(ctx);
Expand All @@ -23,7 +24,7 @@ fn query(ctx: c.omg_context) !void {
};
try util.check_error(c.omg_query_repo_discussion_category(ctx, "xigua2023", "test-github-api", &out));
defer {
// TODO: free out
c.omg_free_repo_discussion_category(&out);
}
}

Expand Down

0 comments on commit adb15c7

Please sign in to comment.