Fixed use after free.
authorArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 14:13:08 +0000 (15:13 +0100)
committerArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 14:13:08 +0000 (15:13 +0100)
winpr/libwinpr/environment/environment.c

index 70768be..0fd4e86 100644 (file)
@@ -390,11 +390,17 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
                                {
                                        while ((offset + mergeLength + 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;
                                        }
 
                                        foundMerge = 1;