Commit Diff


commit - 8d212112582e612c39aa399858bc0b10c74782d0
commit + e08111f29f40db6013de92a2f63265255d647ee8
blob - c05b5d3f676d0d0b4f723b3825e8cf02afd3fa47
blob + 232ab4c8aa553e2c4cf0a880fe27470a40b63e0f
--- tog/tog.c
+++ tog/tog.c
@@ -6995,13 +6995,7 @@ cmd_blame(int argc, char *argv[])
 		    commit_id_str, GOT_OBJ_TYPE_COMMIT, &tog_refs, repo);
 	}
 	if (error != NULL)
-		goto done;
-
-	view = view_open(0, 0, 0, 0, TOG_VIEW_BLAME);
-	if (view == NULL) {
-		error = got_error_from_errno("view_open");
 		goto done;
-	}
 
 	error = got_object_open_as_commit(&commit, repo, commit_id);
 	if (error)
@@ -7012,10 +7006,19 @@ cmd_blame(int argc, char *argv[])
 	if (error)
 		goto done;
 
+	view = view_open(0, 0, 0, 0, TOG_VIEW_BLAME);
+	if (view == NULL) {
+		error = got_error_from_errno("view_open");
+		goto done;
+	}
 	error = open_blame_view(view, link_target ? link_target : in_repo_path,
 	    commit_id, repo);
-	if (error)
+	if (error != NULL) {
+		if (view->close == NULL)
+			close_blame_view(view);
+		view_close(view);
 		goto done;
+	}
 	if (worktree) {
 		/* Release work tree lock. */
 		got_worktree_close(worktree);
@@ -7028,11 +7031,6 @@ done:
 	free(link_target);
 	free(cwd);
 	free(commit_id);
-	if (error != NULL && view != NULL) {
-		if (view->close == NULL)
-			close_blame_view(view);
-		view_close(view);
-	}
 	if (commit)
 		got_object_commit_close(commit);
 	if (worktree)