diff options
Diffstat (limited to 'gnulib/import/glob.c')
-rw-r--r-- | gnulib/import/glob.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/gnulib/import/glob.c b/gnulib/import/glob.c index 6f57860..f1b20d4 100644 --- a/gnulib/import/glob.c +++ b/gnulib/import/glob.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2019 Free Software Foundation, Inc. +/* Copyright (C) 1991-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -72,6 +72,10 @@ # define __glob glob # define __getlogin_r(buf, len) getlogin_r (buf, len) # define __lstat64(fname, buf) lstat (fname, buf) +# ifdef __MINGW32__ + /* Avoid GCC warning. mingw has an unused __stat64 macro. */ +# undef __stat64 +# endif # define __stat64(fname, buf) stat (fname, buf) # define __fxstatat64(_, d, f, st, flag) fstatat (d, f, st, flag) # define struct_stat64 struct stat @@ -839,10 +843,11 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int), { size_t home_len = strlen (p->pw_dir); size_t rest_len = end_name == NULL ? 0 : strlen (end_name); + /* dirname contains end_name; we can't free it now. */ + char *prev_dirname = + (__glibc_unlikely (malloc_dirname) ? dirname : NULL); char *d; - if (__glibc_unlikely (malloc_dirname)) - free (dirname); malloc_dirname = 0; if (glob_use_alloca (alloca_used, home_len + rest_len + 1)) @@ -853,6 +858,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int), dirname = malloc (home_len + rest_len + 1); if (dirname == NULL) { + free (prev_dirname); scratch_buffer_free (&pwtmpbuf); retval = GLOB_NOSPACE; goto out; @@ -864,6 +870,8 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int), d = mempcpy (d, end_name, rest_len); *d = '\0'; + free (prev_dirname); + dirlen = home_len + rest_len; dirname_modified = 1; } |