summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-02-27 18:35:09 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-02-27 18:35:09 -0800
commitc9d657e320eb40e71695b587dc2e47a9230d05bf (patch)
tree3ef279b286befbd5354a29b7bb00064cc278a025
parentf94b59c49ee64695fd591a9eedf3ceea3737189a (diff)
downloadtxr-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.c4
1 files changed, 3 insertions, 1 deletions
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"),