Commit c980e4703622d93dfeebcd122bc9f747227b55f6

Stefan Sperling 2019-03-15T12:47:15

plug memleak in alloc_ref()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/lib/reference.c b/lib/reference.c
index 5205a7b..f548d7d 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -86,13 +86,13 @@ alloc_ref(struct got_reference **ref, const char *name,
 		return got_error_from_errno();
 
 	memcpy(&(*ref)->ref.ref.sha1, id->sha1, SHA1_DIGEST_LENGTH);
+	(*ref)->flags = flags;
 	(*ref)->ref.ref.name = strdup(name);
 	if ((*ref)->ref.ref.name == NULL) {
 		err = got_error_from_errno();
-		free(*ref);
+		got_ref_close(*ref);
 		*ref = NULL;
 	}
-	(*ref)->flags = flags;
 	return err;
 }