summaryrefslogtreecommitdiffstats
path: root/glob.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-04-21 21:15:24 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-04-21 21:15:24 -0700
commit368a4d05039d41eb31120f8624b9cf7037035d2e (patch)
tree9b064ccd97c5cdc0c0d946ab6efde6a9b48375fe /glob.c
parentc2374487d235c08b71762d2ceb8645d18481c97f (diff)
downloadtxr-368a4d05039d41eb31120f8624b9cf7037035d2e.tar.gz
txr-368a4d05039d41eb31120f8624b9cf7037035d2e.tar.bz2
txr-368a4d05039d41eb31120f8624b9cf7037035d2e.zip
Strengthen against resource leaks upon exceptions.
* glob.c (glob_wrap): Perform argument conversions that might throw before allocating UTF-8 string. * parser.y (text): In the action for SPACE, the lexeme is not needed so free($1) right away. If regex_compile were to throw an exception, that lexeme will leak. * socket.c (getaddrinfo_wrap): Harden against leakage of node_u8 and service_u8 strings with an unwind block. For instance, the hints structure could contain bad values which cause addrinfo_in to throw. * stream.c (make_string_byte_input_stream): Perform possibly throwing argument conversions before allocating resources. * sysif.c (mkdir_wrap, mknod_wrap, chmod_wrap, symlink_wrap, link_wrap, setenv_wrap, crypt_wrap): Likewise. * syslog.c (openlog_wrap, syslog_wrapv): Likewise.
Diffstat (limited to 'glob.c')
-rw-r--r--glob.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/glob.c b/glob.c
index 09151375..c5914b2a 100644
--- a/glob.c
+++ b/glob.c
@@ -66,9 +66,9 @@ static int errfunc_thunk(const char *errpath, int errcode)
val glob_wrap(val pattern, val flags, val errfunc)
{
+ cnum c_flags = c_num(default_arg(flags, zero));
char *pat_u8 = utf8_dup_to(c_str(pattern));
glob_t gl;
- cnum c_flags = c_num(default_arg(flags, zero));
if (s_errfunc) {
free(pat_u8);