Fixed memory leak.
authorArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 16:21:36 +0000 (17:21 +0100)
committerArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 16:21:36 +0000 (17:21 +0100)
winpr/libwinpr/environment/environment.c

index 917e623..fd4a0bb 100644 (file)
@@ -355,11 +355,17 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
 
                while ((offset + length + 8) > cchEnvironmentBlock)
                {
+                       LPCH tmp;
                        cchEnvironmentBlock *= 2;
-                       lpszEnvironmentBlock = (LPCH) realloc(lpszEnvironmentBlock, cchEnvironmentBlock * sizeof(CHAR));
+                       tmp = (LPCH) realloc(lpszEnvironmentBlock, cchEnvironmentBlock * sizeof(CHAR));
 
-                       if (!lpszEnvironmentBlock)
+                       if (!tmp)
+                       {
+                               if (lpszEnvironmentBlock)
+                                       free (lpszEnvironmentBlock);    
                                return NULL;
+                       }
+                       lpszEnvironmentBlock = tmp;
                }
 
                p = &(lpszEnvironmentBlock[offset]);