summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-07-12 13:28:03 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-07-12 13:28:03 +0200
commit4de7f3bfc3ad9b2b22620cbe012a70c1c11b3b17 (patch)
tree3b017827447efeba81440aac939628bb00b8f373
parenta522d8c1e72b3875805750cba9556fd303b9c8b2 (diff)
downloadlibgit2-4de7f3bfc3ad9b2b22620cbe012a70c1c11b3b17.tar.gz
filter: make sure to close the stream even on errorcmn/checkout-free-stream
When the stream list init or write fail, we must also make sure to close the stream, as that's the function contract.
-rw-r--r--src/filter.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/filter.c b/src/filter.c
index 70c4fa382..60473e4e1 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(