Commit 4de7f3bfc3ad9b2b22620cbe012a70c1c11b3b17

Carlos Martín Nieto 2015-07-12T13:28:03

filter: make sure to close the stream even on error When the stream list init or write fail, we must also make sure to close the stream, as that's the function contract.

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(