Merge pull request #35 from ulidtko/fix-broken-mkdir

fix "new.key: Is a directory" and a memleak when generating a keypair
This commit is contained in:
Frank Denis 2017-12-14 16:11:00 +01:00 committed by GitHub
commit f384177a3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -206,7 +206,11 @@ basedir_create_useronly(const char *file)
dir = xstrdup(file);
basename = file_basename(dir);
if (basename != dir) {
if (basename == dir) {
// this is a plain file path relative to CWD
free(dir);
return 0;
} else {
dir[basename - dir - 1] = 0;
}
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
@ -217,8 +221,8 @@ basedir_create_useronly(const char *file)
if (*dir == 0 || _mkdir(dir) == 0 || errno == EEXIST) {
ret = 0;
}
free(dir);
#endif
free(dir);
return ret;
}