- Complete rewrite of environment variable handling to get rid of memory leaks, heap...
[reactos.git] / reactos / lib / msvcrt / stdio / popen.c
index 7b0753b..5c9b558 100644 (file)
@@ -30,12 +30,9 @@ FILE *_popen (const char *cm, const char *md) /* program name, pipe mode */
     return NULL;
 
   szComSpec = getenv("COMSPEC");
-
   if (szComSpec == NULL)
   {
-    szComSpec = strdup("cmd.exe");
-    if (szComSpec == NULL)
-      return NULL;
+    szComSpec = "cmd.exe";
   }
 
   s = max(strrchr(szComSpec, '\\'), strrchr(szComSpec, '/'));
@@ -47,7 +44,6 @@ FILE *_popen (const char *cm, const char *md) /* program name, pipe mode */
   szCmdLine = malloc(strlen(s) + 4 + strlen(cm) + 1);
   if (szCmdLine == NULL)
   {
-    free (szComSpec);
     return NULL;
   }
   
@@ -60,7 +56,6 @@ FILE *_popen (const char *cm, const char *md) /* program name, pipe mode */
 
   if ( !CreatePipe(&hReadPipe,&hWritePipe,&sa,1024))
   {
-    free (szComSpec);
     free (szCmdLine);
     return NULL;
   }
@@ -87,7 +82,6 @@ FILE *_popen (const char *cm, const char *md) /* program name, pipe mode */
                          NULL,
                          &StartupInfo,
                          &ProcessInformation);
-  free (szComSpec);
   free (szCmdLine);
 
   if (result == FALSE)
@@ -152,9 +146,7 @@ FILE *_wpopen (const wchar_t *cm, const wchar_t *md) /* program name, pipe mode
 
   if (szComSpec == NULL)
   {
-    szComSpec = _wcsdup(L"cmd.exe");
-    if (szComSpec == NULL)
-      return NULL;
+    szComSpec = L"cmd.exe";
   }
 
   s = max(wcsrchr(szComSpec, L'\\'), wcsrchr(szComSpec, L'/'));
@@ -166,7 +158,6 @@ FILE *_wpopen (const wchar_t *cm, const wchar_t *md) /* program name, pipe mode
   szCmdLine = malloc((wcslen(s) + 4 + wcslen(cm) + 1) * sizeof(wchar_t));
   if (szCmdLine == NULL)
   {
-    free (szComSpec);
     return NULL;
   }
   
@@ -179,7 +170,6 @@ FILE *_wpopen (const wchar_t *cm, const wchar_t *md) /* program name, pipe mode
 
   if ( !CreatePipe(&hReadPipe,&hWritePipe,&sa,1024))
   {
-    free (szComSpec);
     free (szCmdLine);
     return NULL;
   }
@@ -206,7 +196,6 @@ FILE *_wpopen (const wchar_t *cm, const wchar_t *md) /* program name, pipe mode
                          NULL,
                          &StartupInfo,
                          &ProcessInformation);
-  free (szComSpec);
   free (szCmdLine);
 
   if (result == FALSE)