[PATCH:libX11 07/12] Avoid memory leak/corruption if realloc fails in Xregion.h:MEMCHECK macro
Matthieu Herrb
matthieu.herrb at laas.fr
Sun Aug 11 03:37:52 PDT 2013
On Sat, Aug 10, 2013 at 01:55:04PM -0700, Alan Coopersmith wrote:
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
I'm wondering here if firstrect() shouldn't be free()'d when Xrealloc
fails. I can't tell from reading the code what will happen if Xrealloc
fails (since most of the callers are void functions that don't have a
way to propagate the error).
> ---
> 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
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
--
Matthieu Herrb
More information about the xorg-devel
mailing list