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.
This commit is contained in:
Carlos Martín Nieto 2015-06-10 11:08:05 +02:00
parent 969d4b703c
commit 0137aba568

View File

@ -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;