Commit 0137aba5 by Carlos Martín Nieto

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.
parent 969d4b70
...@@ -887,7 +887,7 @@ int git_filter_list_stream_file( ...@@ -887,7 +887,7 @@ int git_filter_list_stream_file(
git_vector filter_streams = GIT_VECTOR_INIT; git_vector filter_streams = GIT_VECTOR_INIT;
git_writestream *stream_start; git_writestream *stream_start;
ssize_t readlen; ssize_t readlen;
int fd, error; int fd = -1, error;
if ((error = stream_list_init( if ((error = stream_list_init(
&stream_start, &filter_streams, filters, target)) < 0 || &stream_start, &filter_streams, filters, target)) < 0 ||
...@@ -909,9 +909,10 @@ int git_filter_list_stream_file( ...@@ -909,9 +909,10 @@ int git_filter_list_stream_file(
else if (readlen < 0) else if (readlen < 0)
error = readlen; error = readlen;
p_close(fd);
done: done:
if (fd >= 0)
p_close(fd);
stream_list_free(&filter_streams); stream_list_free(&filter_streams);
git_buf_free(&abspath); git_buf_free(&abspath);
return error; return error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment