plug a memory leak; parsed tree entries were not freed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
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)