diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-02-27 18:35:09 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-02-27 18:35:09 -0800 |
commit | c9d657e320eb40e71695b587dc2e47a9230d05bf (patch) | |
tree | 3ef279b286befbd5354a29b7bb00064cc278a025 | |
parent | f94b59c49ee64695fd591a9eedf3ceea3737189a (diff) | |
download | txr-c9d657e320eb40e71695b587dc2e47a9230d05bf.tar.gz txr-c9d657e320eb40e71695b587dc2e47a9230d05bf.tar.bz2 txr-c9d657e320eb40e71695b587dc2e47a9230d05bf.zip |
Fix descriptor leak on exception in open-fileno.
* stream.c (open_fileno): If w_fdopen fails, close the
file descriptor before throwing exception.
-rw-r--r-- | stream.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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"), |