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>
master
Benno Schulenberg 2016-04-04 21:04:25 +02:00
parent 284877104f
commit 33a6f6a1b6
1 changed files with 3 additions and 7 deletions

View File

@ -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();