From: Stefan Beller Date: Wed, 30 Mar 2016 00:38:52 GMT Subject: [PATCH 5/6] bundle: don't leak an fd in case of early return Message-ID: <1459298333-21899-6-git-send-email-sbeller@google.com> In-Reply-To: <1459298333-21899-1-git-send-email-sbeller@google.com> In successful operation `write_pack_data` will close the `bundle_fd`, but when we exit early, we need to take care of the file descriptor ourselves. Signed-off-by: Stefan Beller --- bundle.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bundle.c b/bundle.c index 506ac49..04d62af 100644 --- a/bundle.c +++ b/bundle.c @@ -434,8 +434,11 @@ int create_bundle(struct bundle_header *header, const char *path, init_revisions(&revs, NULL); /* write prerequisites */ - if (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv)) + if (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv)) { + if (!bundle_to_stdout) + close(bundle_fd); return -1; + } argc = setup_revisions(argc, argv, &revs, NULL); @@ -447,8 +450,11 @@ int create_bundle(struct bundle_header *header, const char *path, ref_count = write_bundle_refs(bundle_fd, &revs); if (!ref_count) die(_("Refusing to create empty bundle.")); - else if (ref_count < 0) + else if (ref_count < 0) { + if (!bundle_to_stdout) + close(bundle_fd); return -1; + } /* write pack */ if (write_pack_data(bundle_fd, &revs)) -- 2.8.0.8.g27a27a6.dirty