Skip to content

Commit 0137aba

Browse files
committed
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.
1 parent 969d4b7 commit 0137aba

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/filter.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ int git_filter_list_stream_file(
887887
git_vector filter_streams = GIT_VECTOR_INIT;
888888
git_writestream *stream_start;
889889
ssize_t readlen;
890-
int fd, error;
890+
int fd = -1, error;
891891

892892
if ((error = stream_list_init(
893893
&stream_start, &filter_streams, filters, target)) < 0 ||
@@ -909,9 +909,10 @@ int git_filter_list_stream_file(
909909
else if (readlen < 0)
910910
error = readlen;
911911

912-
p_close(fd);
913912

914913
done:
914+
if (fd >= 0)
915+
p_close(fd);
915916
stream_list_free(&filter_streams);
916917
git_buf_free(&abspath);
917918
return error;

0 commit comments

Comments
 (0)