Commit Diff


commit - d639f28bed6c07bf171d552905c55829117715da
commit + 21c2d8be42605670e7037d011fea06c5efd5f725
blob - 3e6b04e4af30b1ecf1c809f6bbb9ec651bc524f2
blob + 373ce90b8c88da56713540961da644b3b28c4984
--- got/got.c
+++ got/got.c
@@ -1918,19 +1918,11 @@ done:
 		const struct got_error *close_err = got_repo_close(repo);
 		if (error == NULL)
 			error = close_err;
-	}
-	TAILQ_FOREACH(pe, &refs, entry) {
-		free((void *)pe->path);
-		free(pe->data);
 	}
-	got_pathlist_free(&refs);
-	TAILQ_FOREACH(pe, &symrefs, entry) {
-		free((void *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&symrefs);
-	got_pathlist_free(&wanted_branches);
-	got_pathlist_free(&wanted_refs);
+	got_pathlist_free(&refs, GOT_PATHLIST_FREE_ALL);
+	got_pathlist_free(&symrefs, GOT_PATHLIST_FREE_ALL);
+	got_pathlist_free(&wanted_branches, GOT_PATHLIST_FREE_NONE);
+	got_pathlist_free(&wanted_refs, GOT_PATHLIST_FREE_NONE);
 	free(pack_hash);
 	free(proto);
 	free(host);
@@ -2735,18 +2727,10 @@ done:
 		if (error == NULL)
 			error = pack_err;
 	}
-	TAILQ_FOREACH(pe, &refs, entry) {
-		free((void *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&refs);
-	TAILQ_FOREACH(pe, &symrefs, entry) {
-		free((void *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&symrefs);
-	got_pathlist_free(&wanted_branches);
-	got_pathlist_free(&wanted_refs);
+	got_pathlist_free(&refs, GOT_PATHLIST_FREE_ALL);
+	got_pathlist_free(&symrefs, GOT_PATHLIST_FREE_ALL);
+	got_pathlist_free(&wanted_branches, GOT_PATHLIST_FREE_NONE);
+	got_pathlist_free(&wanted_refs, GOT_PATHLIST_FREE_NONE);
 	free(id_str);
 	free(cwd);
 	free(repo_path);
@@ -3180,7 +3164,7 @@ done:
 		got_ref_close(head_ref);
 	if (ref)
 		got_ref_close(ref);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_NONE);
 	free(commit_id_str);
 	free(commit_id);
 	free(repo_path);
@@ -3613,9 +3597,7 @@ done:
 			error = pack_err;
 	}
 	free(worktree_path);
-	TAILQ_FOREACH(pe, &paths, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
 	free(commit_id);
 	free(commit_id_str);
 	return error;
@@ -4309,7 +4291,6 @@ print_commits(struct got_object_id *root_id, struct go
 	struct got_object_qid *qid;
 	struct got_commit_object *commit;
 	struct got_pathlist_head changed_paths;
-	struct got_pathlist_entry *pe;
 
 	STAILQ_INIT(&reversed_commits);
 	TAILQ_INIT(&changed_paths);
@@ -4371,11 +4352,8 @@ print_commits(struct got_object_id *root_id, struct go
 			}
 			if (have_match == 0) {
 				got_object_commit_close(commit);
-				TAILQ_FOREACH(pe, &changed_paths, entry) {
-					free((char *)pe->path);
-					free(pe->data);
-				}
-				got_pathlist_free(&changed_paths);
+				got_pathlist_free(&changed_paths,
+				    GOT_PATHLIST_FREE_ALL);
 				continue;
 			}
 		}
@@ -4404,11 +4382,7 @@ print_commits(struct got_object_id *root_id, struct go
 		    (end_id && got_object_id_cmp(&id, end_id) == 0))
 			break;
 
-		TAILQ_FOREACH(pe, &changed_paths, entry) {
-			free((char *)pe->path);
-			free(pe->data);
-		}
-		got_pathlist_free(&changed_paths);
+		got_pathlist_free(&changed_paths, GOT_PATHLIST_FREE_ALL);
 	}
 	if (reverse_display_order) {
 		STAILQ_FOREACH(qid, &reversed_commits, entry) {
@@ -4437,11 +4411,7 @@ print_commits(struct got_object_id *root_id, struct go
 			got_object_commit_close(commit);
 			if (err)
 				break;
-			TAILQ_FOREACH(pe, &changed_paths, entry) {
-				free((char *)pe->path);
-				free(pe->data);
-			}
-			got_pathlist_free(&changed_paths);
+			got_pathlist_free(&changed_paths, GOT_PATHLIST_FREE_ALL);
 		}
 	}
 done:
@@ -4450,11 +4420,7 @@ done:
 		STAILQ_REMOVE_HEAD(&reversed_commits, entry);
 		got_object_qid_free(qid);
 	}
-	TAILQ_FOREACH(pe, &changed_paths, entry) {
-		free((char *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&changed_paths);
+	got_pathlist_free(&changed_paths, GOT_PATHLIST_FREE_ALL);
 	if (search_pattern)
 		regfree(&regex);
 	got_commit_graph_close(graph);
@@ -5051,7 +5017,6 @@ cmd_diff(int argc, char *argv[])
 	const char *errstr;
 	struct got_reflist_head refs;
 	struct got_pathlist_head diffstat_paths, paths;
-	struct got_pathlist_entry *pe;
 	FILE *f1 = NULL, *f2 = NULL, *outfile = NULL;
 	int fd1 = -1, fd2 = -1;
 	int *pack_fds = NULL;
@@ -5481,14 +5446,8 @@ done:
 		if (error == NULL)
 			error = pack_err;
 	}
-	TAILQ_FOREACH(pe, &paths, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&paths);
-	TAILQ_FOREACH(pe, &diffstat_paths, entry) {
-		free((char *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&diffstat_paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
+	got_pathlist_free(&diffstat_paths, GOT_PATHLIST_FREE_ALL);
 	got_ref_list_free(&refs);
 	if (outfile && fclose(outfile) == EOF && error == NULL)
 		error = got_error_from_errno("fclose");
@@ -6260,7 +6219,6 @@ cmd_status(int argc, char *argv[])
 	struct got_status_arg st;
 	char *cwd = NULL;
 	struct got_pathlist_head paths;
-	struct got_pathlist_entry *pe;
 	int ch, i, no_ignores = 0;
 	int *pack_fds = NULL;
 
@@ -6357,9 +6315,7 @@ done:
 			error = pack_err;
 	}
 
-	TAILQ_FOREACH(pe, &paths, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
 	free(cwd);
 	return error;
 }
@@ -6893,7 +6849,6 @@ cmd_branch(int argc, char *argv[])
 	const char *delref = NULL, *commit_id_arg = NULL;
 	struct got_reference *ref = NULL;
 	struct got_pathlist_head paths;
-	struct got_pathlist_entry *pe;
 	struct got_object_id *commit_id = NULL;
 	char *commit_id_str = NULL;
 	int *pack_fds = NULL;
@@ -7092,9 +7047,7 @@ done:
 	free(repo_path);
 	free(commit_id);
 	free(commit_id_str);
-	TAILQ_FOREACH(pe, &paths, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
 	return error;
 }
 
@@ -7887,9 +7840,7 @@ done:
 		if (error == NULL)
 			error = pack_err;
 	}
-	TAILQ_FOREACH(pe, &paths, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
 	free(cwd);
 	return error;
 }
@@ -8054,9 +8005,7 @@ done:
 		if (error == NULL)
 			error = pack_err;
 	}
-	TAILQ_FOREACH(pe, &paths, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
 	free(cwd);
 	return error;
 }
@@ -9461,14 +9410,12 @@ done:
 	}
 	if (ref)
 		got_ref_close(ref);
-	got_pathlist_free(&branches);
-	got_pathlist_free(&tags);
+	got_pathlist_free(&branches, GOT_PATHLIST_FREE_NONE);
+	got_pathlist_free(&tags, GOT_PATHLIST_FREE_NONE);
 	got_ref_list_free(&all_branches);
 	got_ref_list_free(&all_tags);
-	got_pathlist_free(&delete_args);
-	TAILQ_FOREACH(pe, &delete_branches, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&delete_branches);
+	got_pathlist_free(&delete_args, GOT_PATHLIST_FREE_NONE);
+	got_pathlist_free(&delete_branches, GOT_PATHLIST_FREE_PATH);
 	free(cwd);
 	free(repo_path);
 	free(proto);
@@ -10531,7 +10478,7 @@ cmd_rebase(int argc, char *argv[])
 			error = got_worktree_checkout_files(worktree,
 			    &paths, repo, update_progress, &upa,
 			    check_cancelled, NULL);
-			got_pathlist_free(&paths);
+			got_pathlist_free(&paths, GOT_PATHLIST_FREE_NONE);
 			if (error)
 				goto done;
 			if (upa.did_something) {
@@ -10629,13 +10576,13 @@ cmd_rebase(int argc, char *argv[])
 				if (error)
 					goto done;
 			}
-			got_worktree_rebase_pathlist_free(&merged_paths);
+			got_pathlist_free(&merged_paths, GOT_PATHLIST_FREE_PATH);
 			break;
 		}
 
 		error = rebase_commit(&merged_paths, worktree, fileindex,
 		    tmp_branch, committer, commit_id, repo);
-		got_worktree_rebase_pathlist_free(&merged_paths);
+		got_pathlist_free(&merged_paths, GOT_PATHLIST_FREE_PATH);
 		if (error)
 			goto done;
 	}
@@ -11952,7 +11899,8 @@ cmd_histedit(int argc, char *argv[])
 				error = got_worktree_status(worktree, &paths,
 				    repo, 0, check_local_changes, &have_changes,
 				    check_cancelled, NULL);
-				got_pathlist_free(&paths);
+				got_pathlist_free(&paths,
+				    GOT_PATHLIST_FREE_NONE);
 				if (error) {
 					if (error->code != GOT_ERR_CANCELLED)
 						goto done;
@@ -12012,7 +11960,7 @@ cmd_histedit(int argc, char *argv[])
 				if (error)
 					goto done;
 			}
-			got_worktree_rebase_pathlist_free(&merged_paths);
+			got_pathlist_free(&merged_paths, GOT_PATHLIST_FREE_PATH);
 			break;
 		}
 
@@ -12024,7 +11972,7 @@ cmd_histedit(int argc, char *argv[])
 			printf("Stopping histedit for amending commit %s\n",
 			    id_str);
 			free(id_str);
-			got_worktree_rebase_pathlist_free(&merged_paths);
+			got_pathlist_free(&merged_paths, GOT_PATHLIST_FREE_PATH);
 			error = got_worktree_histedit_postpone(worktree,
 			    fileindex);
 			goto done;
@@ -12039,7 +11987,7 @@ cmd_histedit(int argc, char *argv[])
 
 		error = histedit_commit(&merged_paths, worktree, fileindex,
 		    tmp_branch, hle, committer, repo);
-		got_worktree_rebase_pathlist_free(&merged_paths);
+		got_pathlist_free(&merged_paths, GOT_PATHLIST_FREE_PATH);
 		if (error)
 			goto done;
 	}
@@ -12585,7 +12533,6 @@ cmd_stage(int argc, char *argv[])
 	struct got_worktree *worktree = NULL;
 	char *cwd = NULL;
 	struct got_pathlist_head paths;
-	struct got_pathlist_entry *pe;
 	int ch, list_stage = 0, pflag = 0, allow_bad_symlinks = 0;
 	FILE *patch_script_file = NULL;
 	const char *patch_script_path = NULL;
@@ -12698,9 +12645,7 @@ done:
 		if (error == NULL)
 			error = pack_err;
 	}
-	TAILQ_FOREACH(pe, &paths, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
 	free(cwd);
 	return error;
 }
@@ -12722,7 +12667,6 @@ cmd_unstage(int argc, char *argv[])
 	struct got_worktree *worktree = NULL;
 	char *cwd = NULL;
 	struct got_pathlist_head paths;
-	struct got_pathlist_entry *pe;
 	int ch, pflag = 0;
 	struct got_update_progress_arg upa;
 	FILE *patch_script_file = NULL;
@@ -12821,9 +12765,7 @@ done:
 		if (error == NULL)
 			error = pack_err;
 	}
-	TAILQ_FOREACH(pe, &paths, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
 	free(cwd);
 	return error;
 }
@@ -13264,7 +13206,6 @@ cmd_info(int argc, char *argv[])
 	struct got_worktree *worktree = NULL;
 	char *cwd = NULL, *id_str = NULL;
 	struct got_pathlist_head paths;
-	struct got_pathlist_entry *pe;
 	char *uuidstr = NULL;
 	int ch, show_files = 0;
 
@@ -13363,9 +13304,7 @@ cmd_info(int argc, char *argv[])
 done:
 	if (worktree)
 		got_worktree_close(worktree);
-	TAILQ_FOREACH(pe, &paths, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
 	free(cwd);
 	free(id_str);
 	free(uuidstr);
blob - c8bff38153e5c402844c563465693064b7257d24
blob + e56af526574e829f6648d2978d85ee8b14af9cd2
--- gotadmin/gotadmin.c
+++ gotadmin/gotadmin.c
@@ -827,7 +827,7 @@ done:
 		if (error == NULL)
 			error = pack_err;
 	}
-	got_pathlist_free(&exclude_args);
+	got_pathlist_free(&exclude_args, GOT_PATHLIST_FREE_NONE);
 	got_ref_list_free(&exclude_refs);
 	got_ref_list_free(&include_refs);
 	free(id_str);
blob - 7cb114b362ef4f4a6d3f385fb37066d5a97691bd
blob + aa121bb3af4c0cba66fb0d062f2f6a8cc33fdd27
--- include/got_path.h
+++ include/got_path.h
@@ -92,8 +92,14 @@ const struct got_error *got_pathlist_insert(struct got
 const struct got_error *got_pathlist_append(struct got_pathlist_head *,
     const char *, void *);
 
+/* Flags passed to got_pathlist_free() to control which pointers are freed. */
+#define GOT_PATHLIST_FREE_NONE	0	  /* pathlist entry only */
+#define GOT_PATHLIST_FREE_PATH	(1 << 0)  /* entry and path pointer */
+#define GOT_PATHLIST_FREE_DATA	(1 << 1)  /* entry and data pointer */
+#define GOT_PATHLIST_FREE_ALL	(GOT_PATHLIST_FREE_PATH|GOT_PATHLIST_FREE_DATA)
+
 /* Free resources allocated for a path list. */
-void got_pathlist_free(struct got_pathlist_head *);
+void got_pathlist_free(struct got_pathlist_head *, int);
 
 /* Attempt to create a directory at a given path. */
 const struct got_error *got_path_mkdir(const char *);
blob - 3d11d1ed4657d8fa1f4809c2b04fe5b891fea563
blob + d3c26b9a044948f5b93e8f2f6adf673b8dd7e599
--- include/got_worktree.h
+++ include/got_worktree.h
@@ -287,7 +287,7 @@ const struct got_error *got_worktree_rebase_in_progres
  * progress callback. Also populate a list of affected paths which should
  * be passed to got_worktree_rebase_commit() after a conflict-free merge.
  * This list must be initialized with TAILQ_INIT() and disposed of with
- * got_worktree_rebase_pathlist_free().
+ * got_pathlist_free(list, GOT_PATHLIST_FREE_PATH).
  */
 const struct got_error *got_worktree_rebase_merge_files(
     struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
@@ -305,9 +305,6 @@ const struct got_error *got_worktree_rebase_commit(str
     struct got_reference *, const char *, struct got_commit_object *,
     struct got_object_id *, struct got_repository *);
 
-/* Free a list of merged paths from got_worktree_merge_files. */
-void got_worktree_rebase_pathlist_free(struct got_pathlist_head *);
-
 /* Postpone the rebase operation. Should be called after a merge conflict. */
 const struct got_error *got_worktree_rebase_postpone(struct got_worktree *,
     struct got_fileindex *);
@@ -362,7 +359,7 @@ const struct got_error *got_worktree_histedit_in_progr
  * progress callback. Also populate a list of affected paths which should
  * be passed to got_worktree_histedit_commit() after a conflict-free merge.
  * This list must be initialized with TAILQ_INIT() and disposed of with
- * got_worktree_rebase_pathlist_free().
+ * got_pathlist_free(list, GOT_PATHLIST_FREE_PATH).
  */
 const struct got_error *got_worktree_histedit_merge_files(
     struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
blob - fa7413ae8411122c7687d51f8121007fc1d7dc5c
blob + 2c31b3baf9ef7b0f28c232487805460cb4fa1a6a
--- lib/fetch.c
+++ lib/fetch.c
@@ -535,25 +535,13 @@ done:
 	free(packpath);
 	free(progress);
 
-	TAILQ_FOREACH(pe, &have_refs, entry) {
-		free((char *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&have_refs);
+	got_pathlist_free(&have_refs, GOT_PATHLIST_FREE_ALL);
 	got_ref_list_free(&my_refs);
 	if (err) {
 		free(*pack_hash);
 		*pack_hash = NULL;
-		TAILQ_FOREACH(pe, refs, entry) {
-			free((void *)pe->path);
-			free(pe->data);
-		}
-		got_pathlist_free(refs);
-		TAILQ_FOREACH(pe, symrefs, entry) {
-			free((void *)pe->path);
-			free(pe->data);
-		}
-		got_pathlist_free(symrefs);
+		got_pathlist_free(refs, GOT_PATHLIST_FREE_ALL);
+		got_pathlist_free(symrefs, GOT_PATHLIST_FREE_ALL);
 	}
 	return err;
 }
blob - 483771419c2b844e139052425b5c7089f73bb68a
blob + d2a03e1d84e482a3a77be76620b440f9c795ff85
--- lib/fileindex.c
+++ lib/fileindex.c
@@ -976,16 +976,6 @@ read_dirlist(struct got_pathlist_head *dirlist, DIR *d
 	}
 
 	return err;
-}
-
-static void
-free_dirlist(struct got_pathlist_head *dirlist)
-{
-	struct got_pathlist_entry *dle;
-
-	TAILQ_FOREACH(dle, dirlist, entry)
-		free(dle->data);
-	got_pathlist_free(dirlist);
 }
 
 static int
@@ -1076,7 +1066,7 @@ walk_dir(struct got_pathlist_entry **next, struct got_
 			err = got_error_from_errno2("closedir", subdirpath);
 		free(subpath);
 		free(subdirpath);
-		free_dirlist(&subdirlist);
+		got_pathlist_free(&subdirlist, GOT_PATHLIST_FREE_DATA);
 		if (err)
 			return err;
 	}
@@ -1235,7 +1225,7 @@ got_fileindex_diff_dir(struct got_fileindex *fileindex
 
 	if (closedir(dir) == -1 && err == NULL)
 		err = got_error_from_errno2("closedir", path);
-	free_dirlist(&dirlist);
+	got_pathlist_free(&dirlist, GOT_PATHLIST_FREE_DATA);
 	return err;
 }
 
blob - fa3fd1272850220a7010ecf116f1b8f2fdee73b1
blob + 2d6982b9e7830aab3274aa68aa2ade900ffc82d2
--- lib/path.c
+++ lib/path.c
@@ -274,11 +274,19 @@ got_pathlist_append(struct got_pathlist_head *pathlist
 }
 
 void
-got_pathlist_free(struct got_pathlist_head *pathlist)
+got_pathlist_free(struct got_pathlist_head *pathlist, int freemask)
 {
 	struct got_pathlist_entry *pe;
 
 	while ((pe = TAILQ_FIRST(pathlist)) != NULL) {
+		if (freemask & GOT_PATHLIST_FREE_PATH) {
+			free((char *)pe->path);
+			pe->path = NULL;
+		}
+		if (freemask & GOT_PATHLIST_FREE_DATA) {
+			free(pe->data);
+			pe->data = NULL;
+		}
 		TAILQ_REMOVE(pathlist, pe, entry);
 		free(pe);
 	}
blob - 6f22a459dcf584569cb37bce03612894b30cf971
blob + b0c3b7094e4b1c970d1cda630bbf40c4862d3c6f
--- lib/repository.c
+++ lib/repository.c
@@ -785,7 +785,6 @@ got_repo_close(struct got_repository *repo)
 {
 	const struct got_error *err = NULL, *child_err;
 	struct got_packidx_bloom_filter *bf;
-	struct got_pathlist_entry *pe;
 	size_t i;
 
 	for (i = 0; i < repo->pack_cache_size; i++) {
@@ -847,9 +846,7 @@ got_repo_close(struct got_repository *repo)
 		free(repo->extensions[i]);
 	free(repo->extensions);
 
-	TAILQ_FOREACH(pe, &repo->packidx_paths, entry)
-		free((void *)pe->path);
-	got_pathlist_free(&repo->packidx_paths);
+	got_pathlist_free(&repo->packidx_paths, GOT_PATHLIST_FREE_PATH);
 	free(repo);
 
 	return err;
@@ -2171,7 +2168,7 @@ write_tree(struct got_object_id **new_tree_id, const c
 done:
 	if (dir)
 		closedir(dir);
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_NONE);
 	return err;
 }
 
blob - edb3e20183d33860e39b8ec07038fcae745ceb0f
blob + be435b3948bb0c087620071008e5aaef90565f6b
--- lib/send.c
+++ lib/send.c
@@ -725,8 +725,8 @@ done:
 		err = got_error_from_errno("close");
 
 	got_ref_list_free(&refs);
-	got_pathlist_free(&have_refs);
-	got_pathlist_free(&their_refs);
+	got_pathlist_free(&have_refs, GOT_PATHLIST_FREE_NONE);
+	got_pathlist_free(&their_refs, GOT_PATHLIST_FREE_NONE);
 	for (i = 0; i < nours; i++)
 		free(our_ids[i]);
 	free(our_ids);
blob - d535cf87d5de06518314b223a8def80c07ea403b
blob + f4f5fcfcdf51986e308f977d52be4490277e5019
--- lib/worktree.c
+++ lib/worktree.c
@@ -3406,16 +3406,6 @@ status_old(void *arg, struct got_fileindex_entry *ie, 
 		status = GOT_STATUS_DELETE;
 	return (*a->status_cb)(a->status_arg, status, get_staged_status(ie),
 	    ie->path, &blob_id, NULL, &commit_id, -1, NULL);
-}
-
-static void
-free_ignorelist(struct got_pathlist_head *ignorelist)
-{
-	struct got_pathlist_entry *pe;
-
-	TAILQ_FOREACH(pe, ignorelist, entry)
-		free((char *)pe->path);
-	got_pathlist_free(ignorelist);
 }
 
 static void
@@ -3425,10 +3415,10 @@ free_ignores(struct got_pathlist_head *ignores)
 
 	TAILQ_FOREACH(pe, ignores, entry) {
 		struct got_pathlist_head *ignorelist = pe->data;
-		free_ignorelist(ignorelist);
-		free((char *)pe->path);
+
+		got_pathlist_free(ignorelist, GOT_PATHLIST_FREE_PATH);
 	}
-	got_pathlist_free(ignores);
+	got_pathlist_free(ignores, GOT_PATHLIST_FREE_PATH);
 }
 
 static const struct got_error *
@@ -3482,7 +3472,7 @@ done:
 	free(line);
 	if (err || pe == NULL) {
 		free(dirpath);
-		free_ignorelist(ignorelist);
+		got_pathlist_free(ignorelist, GOT_PATHLIST_FREE_PATH);
 	}
 	return err;
 }
@@ -5780,7 +5770,7 @@ write_tree(struct got_object_id **new_tree_id, int *ne
 	/* Write new list of entries; deleted entries have been dropped. */
 	err = got_object_tree_create(new_tree_id, &paths, *nentries, repo);
 done:
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_NONE);
 	return err;
 }
 
@@ -6240,9 +6230,10 @@ done:
 		err = unlockerr;
 	TAILQ_FOREACH(pe, &commitable_paths, entry) {
 		struct got_commitable *ct = pe->data;
+
 		free_commitable(ct);
 	}
-	got_pathlist_free(&commitable_paths);
+	got_pathlist_free(&commitable_paths, GOT_PATHLIST_FREE_NONE);
 	if (diff_path && unlink(diff_path) == -1 && err == NULL)
 		err = got_error_from_errno2("unlink", diff_path);
 	free(diff_path);
@@ -6589,17 +6580,6 @@ collect_merged_paths(void *arg, unsigned char status, 
 	if (err || new == NULL)
 		free(p);
 	return err;
-}
-
-void
-got_worktree_rebase_pathlist_free(struct got_pathlist_head *merged_paths)
-{
-	struct got_pathlist_entry *pe;
-
-	TAILQ_FOREACH(pe, merged_paths, entry)
-		free((char *)pe->path);
-
-	got_pathlist_free(merged_paths);
 }
 
 static const struct got_error *
@@ -7955,9 +7935,10 @@ got_worktree_merge_commit(struct got_object_id **new_c
 done:
 	TAILQ_FOREACH(pe, &commitable_paths, entry) {
 		struct got_commitable *ct = pe->data;
+
 		free_commitable(ct);
 	}
-	got_pathlist_free(&commitable_paths);
+	got_pathlist_free(&commitable_paths, GOT_PATHLIST_FREE_NONE);
 	free(fileindex_path);
 	return err;
 }
blob - c5187ac077f1a2bce176f2378882a6f94b7cdf3b
blob + c2b23a762db0ab53b3f2b625b26efb74dddcd5c5
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
@@ -759,11 +759,7 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 		    "pack file checksum mismatch");
 	}
 done:
-	TAILQ_FOREACH(pe, &symrefs, entry) {
-		free((void *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&symrefs);
+	got_pathlist_free(&symrefs, GOT_PATHLIST_FREE_ALL);
 	free(have);
 	free(want);
 	free(id_str);
@@ -784,7 +780,6 @@ main(int argc, char **argv)
 	struct got_pathlist_head have_refs;
 	struct got_pathlist_head wanted_branches;
 	struct got_pathlist_head wanted_refs;
-	struct got_pathlist_entry *pe;
 	struct got_imsg_fetch_request fetch_req;
 	struct got_imsg_fetch_have_ref href;
 	struct got_imsg_fetch_wanted_branch wbranch;
@@ -1002,14 +997,8 @@ main(int argc, char **argv)
 	    fetch_req.fetch_all_branches, &wanted_branches,
 	    &wanted_refs, fetch_req.list_refs_only, &ibuf);
 done:
-	TAILQ_FOREACH(pe, &have_refs, entry) {
-		free((char *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&have_refs);
-	TAILQ_FOREACH(pe, &wanted_branches, entry)
-		free((char *)pe->path);
-	got_pathlist_free(&wanted_branches);
+	got_pathlist_free(&have_refs, GOT_PATHLIST_FREE_ALL);
+	got_pathlist_free(&wanted_branches, GOT_PATHLIST_FREE_PATH);
 	if (fetchfd != -1 && close(fetchfd) == -1 && err == NULL)
 		err = got_error_from_errno("close");
 	if (packfd != -1 && close(packfd) == -1 && err == NULL)
blob - 25ceb461a55b156e97ba7cb19ae2652323c8821f
blob + 656b13122b6f3d7d7e5f8f57d12e56cb416e130a
--- libexec/got-send-pack/got-send-pack.c
+++ libexec/got-send-pack/got-send-pack.c
@@ -591,11 +591,7 @@ send_pack(int fd, struct got_pathlist_head *refs,
 
 	err = send_done(ibuf);
 done:
-	TAILQ_FOREACH(pe, &their_refs, entry) {
-		free((void *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&their_refs);
+	got_pathlist_free(&their_refs, GOT_PATHLIST_FREE_ALL);
 	free(id_str);
 	free(id);
 	free(refname);
@@ -612,7 +608,6 @@ main(int argc, char **argv)
 	struct imsg imsg;
 	struct got_pathlist_head refs;
 	struct got_pathlist_head delete_refs;
-	struct got_pathlist_entry *pe;
 	struct got_imsg_send_request send_req;
 	struct got_imsg_send_ref href;
 	size_t datalen, i;
@@ -735,16 +730,8 @@ main(int argc, char **argv)
 
 	err = send_pack(sendfd, &refs, &delete_refs, &ibuf);
 done:
-	TAILQ_FOREACH(pe, &refs, entry) {
-		free((char *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&refs);
-	TAILQ_FOREACH(pe, &delete_refs, entry) {
-		free((char *)pe->path);
-		free(pe->data);
-	}
-	got_pathlist_free(&delete_refs);
+	got_pathlist_free(&refs, GOT_PATHLIST_FREE_ALL);
+	got_pathlist_free(&delete_refs, GOT_PATHLIST_FREE_ALL);
 	if (sendfd != -1 && close(sendfd) == -1 && err == NULL)
 		err = got_error_from_errno("close");
 	if (err != NULL && err->code != GOT_ERR_CANCELLED)  {
blob - 1b4e2a08ae74cbaca233fe92241caa8848454f5d
blob + fad15574f54715f8f62105579fbc58c1ca5d1bf1
--- regress/path/path_test.c
+++ regress/path/path_test.c
@@ -165,7 +165,7 @@ path_list(void)
 		i++;
 	}
 
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_NONE);
 	return 1;
 }
 
@@ -202,7 +202,7 @@ path_list_reverse_input(void)
 		i++;
 	}
 
-	got_pathlist_free(&paths);
+	got_pathlist_free(&paths, GOT_PATHLIST_FREE_NONE);
 	return 1;
 }
 
blob - d7fa2c1d153bc59e73ad0c79620bfe35b71ffc14
blob + b3aa6afcd77d0a0e0cca4debbca5263d8a69f68e
--- tog/tog.c
+++ tog/tog.c
@@ -4716,8 +4716,6 @@ write_commit_info(struct got_diff_line **lines, size_t
 		    GOT_DIFF_LINE_CHANGES);
 		if (err)
 			goto done;
-		free((char *)pe->path);
-		free(pe->data);
 	}
 
 	fputc('\n', outfile);
@@ -4742,7 +4740,7 @@ write_commit_info(struct got_diff_line **lines, size_t
 	outoff++;
 	err = add_line_metadata(lines, nlines, outoff, GOT_DIFF_LINE_NONE);
 done:
-	got_pathlist_free(&changed_paths);
+	got_pathlist_free(&changed_paths, GOT_PATHLIST_FREE_ALL);
 	free(id_str);
 	free(logmsg);
 	free(refs_str);