user.exe16: Fix memory leaks in cases when HeapReAlloc fails.
Dmitry Timoshkov
dmitry at baikal.ru
Wed Jun 21 03:24:29 CDT 2017
Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
---
dlls/user.exe16/user.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/dlls/user.exe16/user.c b/dlls/user.exe16/user.c
index aba797debc..a760093cb9 100644
--- a/dlls/user.exe16/user.c
+++ b/dlls/user.exe16/user.c
@@ -3245,8 +3245,11 @@ DWORD WINAPI FormatMessage16(
/* CMF - This makes a BIG assumption about va_list */
while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart)) < 0 || ret >= sz) {
+ LPSTR new_b;
sz = (ret == -1 ? sz + 100 : ret + 1);
- b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
+ new_b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
+ if (!new_b) break;
+ b = new_b;
}
for (x=b; *x; x++) ADD_TO_T(*x);
HeapFree(GetProcessHeap(), 0, b);
@@ -3286,7 +3289,8 @@ DWORD WINAPI FormatMessage16(
}
talloced = strlen(target)+1;
if (nSize && talloced<nSize) {
- target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize);
+ LPSTR new_target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize);
+ if (new_target) target = new_target;
}
TRACE("-- %s\n",debugstr_a(target));
if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
--
2.13.1
More information about the wine-patches
mailing list