Commit 0137aba56863634d81e407152df723d5ad4a97ce

Carlos Martín Nieto 2015-06-10T11:08:05

filter: close the descriptor in case of error When we hit an error writing to the next stream from a file, we jump to 'done' which currently skips over closing the file descriptor. Make sure to close the descriptor if it has been set to a valid value.

diff --git a/src/filter.c b/src/filter.c
index c88fdd4..3c6a0a9 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -887,7 +887,7 @@ int git_filter_list_stream_file(
 	git_vector filter_streams = GIT_VECTOR_INIT;
 	git_writestream *stream_start;
 	ssize_t readlen;
-	int fd, error;
+	int fd = -1, error;
 
 	if ((error = stream_list_init(
 			&stream_start, &filter_streams, filters, target)) < 0 ||
@@ -909,9 +909,10 @@ int git_filter_list_stream_file(
 	else if (readlen < 0)
 		error = readlen;
 
-	p_close(fd);
 
 done:
+	if (fd >= 0)
+		p_close(fd);
 	stream_list_free(&filter_streams);
 	git_buf_free(&abspath);
 	return error;