diff --git a/ProcessWin32.c b/ProcessWin32.c
index 5183e3d2c96ec05345328a98689572b85429cab8..9cd886876c7e451f5961655126e4f00b00d3728c 100644
--- a/ProcessWin32.c
+++ b/ProcessWin32.c
@@ -713,11 +713,10 @@ int kwsysProcess_SetPipeFile(kwsysProcess* cp, int pipe, const char* file)
     *pfile = 0;
   }
   if (file) {
-    *pfile = (char*)malloc(strlen(file) + 1);
+    *pfile = strdup(file);
     if (!*pfile) {
       return 0;
     }
-    strcpy(*pfile, file);
   }
 
   /* If we are redirecting the pipe, do not share it or use a native