Commit 7baf5860e933fb606101bf5c6eba106e914b0fac

Stefan Sperling 2019-03-19T12:37:32

avoid code duplication in error case of open_blob()

diff --git a/lib/object.c b/lib/object.c
index a630dcc..911aa0e 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1057,10 +1057,7 @@ open_blob(struct got_blob_object **blob, struct got_repository *repo,
 done:
 	if (err) {
 		if (*blob) {
-			if ((*blob)->f)
-				fclose((*blob)->f);
-			free((*blob)->read_buf);
-			free((*blob)->data);
+			got_object_blob_close(*blob);
 			free(*blob);
 			*blob = NULL;
 		} else if (outfd != -1)
@@ -1089,7 +1086,7 @@ got_object_blob_close(struct got_blob_object *blob)
 {
 	const struct got_error *err = NULL;
 	free(blob->read_buf);
-	if (fclose(blob->f) != 0)
+	if (blob->f && fclose(blob->f) != 0)
 		err = got_error_from_errno();
 	free(blob->data);
 	free(blob);