Commit 7f11502cb5629607446cbb42652120095794f8e0

Hiltjo Posthuma 2019-08-28T18:48:27

fix possible use-after-free in got_worktree_close()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/lib/worktree.c b/lib/worktree.c
index 8921d44..3991862 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -455,7 +455,6 @@ const struct got_error *
 got_worktree_close(struct got_worktree *worktree)
 {
 	const struct got_error *err = NULL;
-	free(worktree->root_path);
 	free(worktree->repo_path);
 	free(worktree->path_prefix);
 	free(worktree->base_commit_id);
@@ -464,6 +463,7 @@ got_worktree_close(struct got_worktree *worktree)
 		if (close(worktree->lockfd) != 0)
 			err = got_error_from_errno2("close",
 			    got_worktree_get_root_path(worktree));
+	free(worktree->root_path);
 	free(worktree);
 	return err;
 }