From bd234419b81d41152456b9f5e02c2ebcb79b2582 Mon Sep 17 00:00:00 2001 From: Zhang Zhaolong Date: Wed, 11 Mar 2015 13:55:41 +0800 Subject: [PATCH] gdi: fix incorrect usage of realloc. Signed-off-by: Zhang Zhaolong --- libfreerdp/gdi/region.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libfreerdp/gdi/region.c b/libfreerdp/gdi/region.c index 6584d435f..ac72b68e8 100644 --- a/libfreerdp/gdi/region.c +++ b/libfreerdp/gdi/region.c @@ -384,8 +384,15 @@ INLINE int gdi_InvalidateRegion(HGDI_DC hdc, int x, int y, int w, int h) if ((hdc->hwnd->ninvalid + 1) > hdc->hwnd->count) { - hdc->hwnd->count *= 2; - cinvalid = (HGDI_RGN) realloc(cinvalid, sizeof(GDI_RGN) * (hdc->hwnd->count)); + int new_cnt; + HGDI_RGN new_rgn; + + new_cnt = hdc->hwnd->count * 2; + new_rgn = (HGDI_RGN) realloc(cinvalid, sizeof(GDI_RGN) * new_cnt); + if (!new_rgn) + return -1; + hdc->hwnd->count = new_cnt; + cinvalid = new_rgn; } gdi_SetRgn(&cinvalid[hdc->hwnd->ninvalid++], x, y, w, h);