Commit b64b1f953a75e1e6639a1fd16a0dc4ce19f4ae78

Stefan Sperling 2020-01-06T13:10:00

plug a memory leak; parsed tree entries were not freed

diff --git a/lib/got_lib_object_parse.h b/lib/got_lib_object_parse.h
index 08660f2..9a940e3 100644
--- a/lib/got_lib_object_parse.h
+++ b/lib/got_lib_object_parse.h
@@ -34,6 +34,7 @@ struct got_parsed_tree_entry {
 };
 const struct got_error *got_object_parse_tree(struct got_pathlist_head *, int *,
     uint8_t *, size_t);
+void got_object_tree_entries_free(struct got_pathlist_head *);
 
 const struct got_error *got_object_parse_tag(struct got_tag_object **,
     uint8_t *, size_t);
diff --git a/lib/object_parse.c b/lib/object_parse.c
index fe0992a..3449f6b 100644
--- a/lib/object_parse.c
+++ b/lib/object_parse.c
@@ -719,13 +719,25 @@ got_object_parse_tree(struct got_pathlist_head *entries, int *nentries,
 	}
 done:
 	if (err) {
-		got_pathlist_free(entries);
+		got_object_tree_entries_free(entries);
 		*nentries = 0;
 	}
 	return err;
 }
 
 void
+got_object_tree_entries_free(struct got_pathlist_head *entries)
+{
+	struct got_pathlist_entry *pe;
+
+	TAILQ_FOREACH(pe, entries, entry) {
+		struct got_parsed_tree_entry *pte = pe->data;
+		free(pte);
+	}
+	got_pathlist_free(entries);
+}
+
+void
 got_object_tag_close(struct got_tag_object *tag)
 {
 	if (tag->refcnt > 0) {
diff --git a/libexec/got-read-pack/got-read-pack.c b/libexec/got-read-pack/got-read-pack.c
index f130a21..9e71e26 100644
--- a/libexec/got-read-pack/got-read-pack.c
+++ b/libexec/got-read-pack/got-read-pack.c
@@ -203,7 +203,7 @@ tree_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
 
 	err = got_privsep_send_tree(ibuf, &entries, nentries);
 done:
-	got_pathlist_free(&entries);
+	got_object_tree_entries_free(&entries);
 	free(buf);
 	got_object_close(obj);
 	if (err) {
diff --git a/libexec/got-read-tree/got-read-tree.c b/libexec/got-read-tree/got-read-tree.c
index 3e24db2..3607590 100644
--- a/libexec/got-read-tree/got-read-tree.c
+++ b/libexec/got-read-tree/got-read-tree.c
@@ -143,7 +143,7 @@ main(int argc, char *argv[])
 
 		err = got_privsep_send_tree(&ibuf, &entries, nentries);
 done:
-		got_pathlist_free(&entries);
+		got_object_tree_entries_free(&entries);
 		free(buf);
 		if (f) {
 			if (fclose(f) != 0 && err == NULL)