Commit Diff


commit - 21017333f16f38ad9e8eb5d478bddf3397d4af05
commit + 15c388a9fbe0ca9bd3fba71581e55dd5ad6d8c33
blob - 6e1e9e139a552a6791b66e9ba6a53bbf2d8ef886
blob + d6f94939b844a5e06b4b92355a08680544dba996
--- 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);