Commit Diff


commit - bcf5a4329785e99de746fcacadcf0530e5889ef3
commit + f96b13c8aa83acca1d0eea6e9b5bb27a2de82866
blob - 665a8692e199221d7bc06d855a7b147f5856fa8c
blob + db103c537261c1a640f6c43ea2dc989f10dea3a3
--- lib/reference.c
+++ lib/reference.c
@@ -1454,6 +1454,8 @@ delete_packed_ref(struct got_reference *delref, struct
 			    packed_refs_path);
 			goto done;
 		}
+		free(tmppath);
+		tmppath = NULL;
 	}
 done:
 	if (delref->lf == NULL && lf)
@@ -1462,11 +1464,10 @@ done:
 		if (fclose(f) == EOF && err == NULL)
 			err = got_error_from_errno("fclose");
 	}
-	if (tmpf) {
-		unlink(tmppath);
-		if (fclose(tmpf) == EOF && err == NULL)
-			err = got_error_from_errno("fclose");
-	}
+	if (tmppath && unlink(tmppath) == -1 && err == NULL)
+		err = got_error_from_errno2("unlink", tmppath);
+	if (tmpf && fclose(tmpf) == EOF && err == NULL)
+		err = got_error_from_errno("fclose");
 	free(tmppath);
 	free(packed_refs_path);
 	free(line);