[PATCH:libX11 09/22] Avoid memory leak/corruption if realloc fails in Xregion.h:MEMCHECK macro

Alan Coopersmith alan.coopersmith at oracle.com
Mon Aug 12 00:04:00 PDT 2013


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 include/X11/Xregion.h |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/X11/Xregion.h b/include/X11/Xregion.h
index c25d70b..cf10f86 100644
--- a/include/X11/Xregion.h
+++ b/include/X11/Xregion.h
@@ -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];\
          }\
-- 
1.7.9.2



More information about the xorg-devel mailing list