From b67561f84ad8e7ee6687ec3ad11da3cdc93d6543 Mon Sep 17 00:00:00 2001
From: Andy Cedilnik <andy.cedilnik@kitware.com>
Date: Wed, 21 Jan 2004 13:38:09 -0500
Subject: [PATCH] BUG: Fix valgrind error. If working directory is not set do
 not do chdir

---
 ProcessUNIX.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/ProcessUNIX.c b/ProcessUNIX.c
index c9f6315..835173c 100644
--- a/ProcessUNIX.c
+++ b/ProcessUNIX.c
@@ -1044,20 +1044,21 @@ static int kwsysProcessInitialize(kwsysProcess* cp)
   memset(cp->CommandExitCodes, 0, sizeof(int)*cp->NumberOfCommands);
 
   /* Allocate memory to save the real working directory.  */
-  {
+  if ( cp->WorkingDirectory )
+    {
 #if defined(MAXPATHLEN)
-  cp->RealWorkingDirectoryLength = MAXPATHLEN;
+    cp->RealWorkingDirectoryLength = MAXPATHLEN;
 #elif defined(PATH_MAX)
-  cp->RealWorkingDirectoryLength = PATH_MAX;
+    cp->RealWorkingDirectoryLength = PATH_MAX;
 #else
-  cp->RealWorkingDirectoryLength = 4096;
+    cp->RealWorkingDirectoryLength = 4096;
 #endif
-  cp->RealWorkingDirectory = malloc(cp->RealWorkingDirectoryLength);
-  if(!cp->RealWorkingDirectory)
-    {
-    return 0;
+    cp->RealWorkingDirectory = malloc(cp->RealWorkingDirectoryLength);
+    if(!cp->RealWorkingDirectory)
+      {
+      return 0;
+      }
     }
-  }
 
   return 1;
 }
-- 
GitLab