commit 33a6f6a1b643bac50ca59a4cbd861cb4e8a7c45d
parent 284877104fe3ca978da828c301dec87b53a4c60b
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Mon, 4 Apr 2016 21:04:25 +0200
files: do not call free on the result of dirname
This fixes https://savannah.gnu.org/bugs/?47544,
and thus also http://gnats.netbsd.org/51010.
Reported-by: Adrian Siekierka <asiekierka@gmail.com>
Reported-by: Matthew Hall <mhall@mhcomputing.net>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
Diffstat:
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -36,15 +36,11 @@
/* Verify that the containing directory of the given filename exists. */
bool has_valid_path(const char *filename)
{
- char *parentdir;
+ char *namecopy = mallocstrcpy(NULL, filename);
+ char *parentdir = dirname(namecopy);
struct stat parentinfo;
bool validity = FALSE;
- if (strrchr(filename, '/') == NULL)
- parentdir = mallocstrcpy(NULL, ".");
- else
- parentdir = dirname(mallocstrcpy(NULL, filename));
-
if (stat(parentdir, &parentinfo) == -1) {
if (errno == ENOENT)
statusbar(_("Directory '%s' does not exist"), parentdir);
@@ -59,7 +55,7 @@ bool has_valid_path(const char *filename)
validity = TRUE;
}
- free(parentdir);
+ free(namecopy);
if (!validity)
beep();