Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- worktree.c | 14 +++++++++++--- worktree.h | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/worktree.c b/worktree.c index 4c38414..b4e4b57 100644 --- a/worktree.c +++ b/worktree.c @@ -4,14 +4,22 @@ #include "worktree.h" #include "dir.h" +void clear_worktree(struct worktree *wt) +{ + if (!wt) + return; + free(wt->path); + free(wt->id); + free(wt->head_ref); + memset(wt, 0, sizeof(*wt)); +} + void free_worktrees(struct worktree **worktrees) { int i = 0; for (i = 0; worktrees[i]; i++) { - free(worktrees[i]->path); - free(worktrees[i]->id); - free(worktrees[i]->head_ref); + clear_worktree(worktrees[i]); free(worktrees[i]); } free (worktrees); diff --git a/worktree.h b/worktree.h index e89d423..0ba07ab 100644 --- a/worktree.h +++ b/worktree.h @@ -28,6 +28,11 @@ extern struct worktree **get_worktrees(void); extern const char *get_worktree_git_dir(const struct worktree *wt); /* + * Free up the memory for worktree + */ +extern void clear_worktree(struct worktree *); + +/* * Free up the memory for worktree(s) */ extern void free_worktrees(struct worktree **); -- 2.7.0.377.g4cd97dd -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html