From c9d657e320eb40e71695b587dc2e47a9230d05bf Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 27 Feb 2016 18:35:09 -0800 Subject: Fix descriptor leak on exception in open-fileno. * stream.c (open_fileno): If w_fdopen fails, close the file descriptor before throwing exception. --- stream.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'stream.c') diff --git a/stream.c b/stream.c index 849e7570..69251bf9 100644 --- a/stream.c +++ b/stream.c @@ -3150,9 +3150,11 @@ val open_fileno(val fd, val mode_str) struct stdio_mode m; FILE *f = (errno = 0, w_fdopen(c_num(fd), c_str(normalize_mode(&m, mode_str)))); - if (!f) + if (!f) { + close(c_num(fd)); uw_throwf(file_error_s, lit("error opening descriptor ~a: ~d/~s"), fd, num(errno), string_utf8(strerror(errno)), nao); + } return set_mode_props(m, make_stdio_stream(f, format(nil, lit("fd ~d"), -- cgit v1.2.3