summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 76796f4)
raw | patch | inline | side by side (parent: 76796f4)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 30 Jun 2014 06:13:53 +0000 (08:13 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 30 Jun 2014 06:13:53 +0000 (08:13 +0200) |
It may point to static memory.
src/frontend/sock.c | patch | blob | history | |
src/utils/os.c | patch | blob | history |
diff --git a/src/frontend/sock.c b/src/frontend/sock.c
index 845274e95606bde06129e4d676657dd9f6db8342..dd0afa907fbcf5564a05d187db28d9eca3c0ea0b 100644 (file)
--- a/src/frontend/sock.c
+++ b/src/frontend/sock.c
open_unix_sock(listener_t *listener)
{
const char *addr;
+ char *addr_copy;
char *base_dir;
struct sockaddr_un sa;
int status;
sa.sun_family = AF_UNIX;
strncpy(sa.sun_path, addr, sizeof(sa.sun_path));
- base_dir = strdup(addr);
- if (! base_dir) {
+ addr_copy = strdup(addr);
+ if (! addr_copy) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "frontend: strdup failed: %s",
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
- base_dir = dirname(base_dir);
+ base_dir = dirname(addr_copy);
/* ensure that the directory exists */
if (sdb_mkdir_all(base_dir, 0777)) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "frontend: Failed to create directory '%s': %s",
base_dir, sdb_strerror(errno, errbuf, sizeof(errbuf)));
- free(base_dir);
+ free(addr_copy);
return -1;
}
- free(base_dir);
+ free(addr_copy);
if (unlink(addr) && (errno != ENOENT)) {
char errbuf[1024];
diff --git a/src/utils/os.c b/src/utils/os.c
index ecca206a1e57c11d98343c680531373cfd918f24..08cb188d172355126d16f80ed4ae096aad47ff06 100644 (file)
--- a/src/utils/os.c
+++ b/src/utils/os.c
sdb_mkdir_all(const char *pathname, mode_t mode)
{
struct stat st;
+ char *pathname_copy;
char *base_dir;
int status = 0;
/* pathname exists but we cannot access it */
return -1;
- base_dir = strdup(pathname);
- if (! base_dir)
+ pathname_copy = strdup(pathname);
+ if (! pathname_copy)
return -1;
- base_dir = dirname(base_dir);
+ base_dir = dirname(pathname_copy);
status = sdb_mkdir_all(base_dir, mode);
if (! status)
status = mkdir(pathname, mode);
- free(base_dir);
+ free(pathname_copy);
return status;
} /* sdb_mkdir_all */