Commit 9f4f302a43f7e186910d59f9dbe0f839b6f2d565

Stefan Sperling 2022-06-07T16:04:15

free id and path in load_packed_tree_ids() on error, else they would leak pointed out by op@

diff --git a/lib/pack_create.c b/lib/pack_create.c
index c148b0c..fff58b0 100644
--- a/lib/pack_create.c
+++ b/lib/pack_create.c
@@ -1520,13 +1520,21 @@ load_packed_tree_ids(void *arg, struct got_tree_object *tree, time_t mtime,
 	if (tree == NULL) {
 		free(a->id);
 		a->id = got_object_id_dup(id);
-		if (a->id == NULL)
-			return got_error_from_errno("got_object_id_dup");
+		if (a->id == NULL) {
+			err = got_error_from_errno("got_object_id_dup");
+			free(a->dpath);
+			a->dpath = NULL;
+			return err;
+		}
 
 		free(a->dpath);
 		a->dpath = strdup(dpath);
-		if (a->dpath == NULL)
-			return got_error_from_errno("strdup");
+		if (a->dpath == NULL) {
+			err = got_error_from_errno("strdup");
+			free(a->id);
+			a->id = NULL;
+			return err;
+		}
 
 		a->mtime = mtime;
 		return NULL;