Commit 14e805a2ceebb360e0bf8d5c006244d5f8af4741

Edward Thomson 2015-07-24T14:59:38

Merge pull request #3304 from libgit2/cmn/checkout-free-stream filter: make sure to close the stream even on error

diff --git a/src/filter.c b/src/filter.c
index 70c4fa3..60473e4 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -950,18 +950,20 @@ int git_filter_list_stream_data(
 {
 	git_vector filter_streams = GIT_VECTOR_INIT;
 	git_writestream *stream_start;
-	int error = 0;
+	int error = 0, close_error;
 
 	git_buf_sanitize(data);
 
-	if ((error = stream_list_init(
-			&stream_start, &filter_streams, filters, target)) == 0 &&
-		(error =
-			stream_start->write(stream_start, data->ptr, data->size)) == 0)
-		error = stream_start->close(stream_start);
+	if ((error = stream_list_init(&stream_start, &filter_streams, filters, target)) < 0)
+		goto out;
 
+	error = stream_start->write(stream_start, data->ptr, data->size);
+
+out:
+	close_error = stream_start->close(stream_start);
 	stream_list_free(&filter_streams);
-	return error;
+	/* propagate the stream init or write error */
+	return error < 0 ? error : close_error;
 }
 
 int git_filter_list_stream_blob(