Avoid memory leak/corruption if realloc fails in Xregion.h:MEMCHECK macro

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
This commit is contained in:
Alan Coopersmith 2013-08-10 11:27:22 -07:00
parent 453c4ee436
commit 5dc8b5385d

View file

@ -112,10 +112,11 @@ typedef struct _XRegion {
*/
#define MEMCHECK(reg, rect, firstrect){\
if ((reg)->numRects >= ((reg)->size - 1)){\
(firstrect) = (BOX *) Xrealloc \
((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\
if ((firstrect) == 0)\
BoxPtr tmpRect = Xrealloc ((firstrect), \
(2 * (sizeof(BOX)) * ((reg)->size))); \
if (tmpRect == NULL) \
return(0);\
(firstrect) = tmpRect; \
(reg)->size *= 2;\
(rect) = &(firstrect)[(reg)->numRects];\
}\