From: Chris Lamb <lamby@debian.org>
Date: Wed, 24 Jan 2018 22:06:35 +1100
Subject: Use get_current_dir_name over PATHMAX, etc.

---
 src/aof.c | 4 ++--
 src/rdb.c | 7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/aof.c b/src/aof.c
index a2a15e3..cf3ed61 100644
--- a/src/aof.c
+++ b/src/aof.c
@@ -251,13 +251,12 @@ void stopAppendOnly(void) {
 /* Called when the user switches from "appendonly no" to "appendonly yes"
  * at runtime using the CONFIG command. */
 int startAppendOnly(void) {
-    char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */
     int newfd;
 
     newfd = open(server.aof_filename,O_WRONLY|O_APPEND|O_CREAT,0644);
     serverAssert(server.aof_state == AOF_OFF);
     if (newfd == -1) {
-        char *cwdp = getcwd(cwd,MAXPATHLEN);
+        char *cwdp = get_current_dir_name();
 
         serverLog(LL_WARNING,
             "Redis needs to enable the AOF but can't open the "
@@ -265,6 +264,7 @@ int startAppendOnly(void) {
             server.aof_filename,
             cwdp ? cwdp : "unknown",
             strerror(errno));
+        free(cwdp);
         return C_ERR;
     }
     if (hasActiveChildProcess() && server.aof_child_pid == -1) {
diff --git a/src/rdb.c b/src/rdb.c
index 82b4cf5..2635adb 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -1313,7 +1313,6 @@ werr: /* Write error. */
 /* Save the DB on disk. Return C_ERR on error, C_OK on success. */
 int rdbSave(char *filename, rdbSaveInfo *rsi) {
     char tmpfile[256];
-    char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */
     FILE *fp = NULL;
     rio rdb;
     int error = 0;
@@ -1321,13 +1320,14 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) {
     snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
     fp = fopen(tmpfile,"w");
     if (!fp) {
-        char *cwdp = getcwd(cwd,MAXPATHLEN);
+        char *cwdp = get_current_dir_name();
         serverLog(LL_WARNING,
             "Failed opening the RDB file %s (in server root dir %s) "
             "for saving: %s",
             filename,
             cwdp ? cwdp : "unknown",
             strerror(errno));
+        free(cwdp);
         return C_ERR;
     }
 
@@ -1351,7 +1351,7 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) {
     /* Use RENAME to make sure the DB file is changed atomically only
      * if the generate DB file is ok. */
     if (rename(tmpfile,filename) == -1) {
-        char *cwdp = getcwd(cwd,MAXPATHLEN);
+        char *cwdp = get_current_dir_name();
         serverLog(LL_WARNING,
             "Error moving temp DB file %s on the final "
             "destination %s (in server root dir %s): %s",
@@ -1359,6 +1359,7 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) {
             filename,
             cwdp ? cwdp : "unknown",
             strerror(errno));
+        free(cwdp);
         unlink(tmpfile);
         stopSaving(0);
         return C_ERR;
