summaryrefslogtreecommitdiff
path: root/src/common/compat.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-08-04 12:26:35 -0400
committerNick Mathewson <nickm@torproject.org>2017-08-04 12:26:35 -0400
commit89407bedf8980b9dd7a10b268b351e8b2938ac80 (patch)
tree014527f8ae273f5e01e813817f3fd2c5df0cc6cb /src/common/compat.c
parentbfe740f0658dc05e9cc624a46ae21bb098117197 (diff)
downloadtor-89407bedf8980b9dd7a10b268b351e8b2938ac80.tar.gz
tor-89407bedf8980b9dd7a10b268b351e8b2938ac80.zip
Tweak usage of get_current_working_dir() for tor_malloc() paranoia.
We assume that tor_free() is not required to be compatible with the platform malloc(), so we need to use a strdup here.
Diffstat (limited to 'src/common/compat.c')
-rw-r--r--src/common/compat.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 8e3d97420a..f5991a640f 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -2350,7 +2350,15 @@ static char *
alloc_getcwd(void)
{
#ifdef HAVE_GET_CURRENT_DIR_NAME
- return get_current_dir_name();
+ /* Glibc makes this nice and simple for us. */
+ char *cwd = get_current_dir_name();
+ char *result = NULL;
+ if (cwd) {
+ /* We make a copy here, in case tor_malloc() is not malloc(). */
+ result = tor_strdup(cwd);
+ raw_free(cwd); // alias for free to avoid tripping check-spaces.
+ }
+ return result;
#else
size_t size = 1024;
char *buf = NULL;