Skip to content

Commit

Permalink
free category
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Jul 17, 2023
1 parent ce4175e commit d88ab49
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 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
2 changes: 1 addition & 1 deletion tests/discussion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 d88ab49

Please sign in to comment.