From 0fc419314b3bbafa873207dafa57ce92b4b9e1e1 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 14 Jul 2012 11:21:15 -0700 Subject: Backport: RRModeCreate: plug memory leak of newModes if AddResource fails Reported by parfait 1.0: Error: Memory leak (CWE 401) Memory leak of pointer 'newModes' allocated with realloc(((char*)modes), ((num_modes + 1) * 8)) at line 93 of randr/rrmode.c in function 'RRModeCreate'. pointer allocated at line 82 with realloc(((char*)modes), ((num_modes + 1) * 8)). Error: Memory leak (CWE 401) Memory leak of pointer 'newModes' allocated with malloc(8) at line 93 of randr/rrmode.c in function 'RRModeCreate'. pointer allocated at line 84 with malloc(8). Signed-off-by: Alan Coopersmith Reviewed-by: Keith Packard --- nx-X11/programs/Xserver/randr/rrmode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nx-X11/programs/Xserver/randr/rrmode.c b/nx-X11/programs/Xserver/randr/rrmode.c index 09c011350..43ffe0705 100644 --- a/nx-X11/programs/Xserver/randr/rrmode.c +++ b/nx-X11/programs/Xserver/randr/rrmode.c @@ -98,8 +98,10 @@ RRModeCreate (xRRModeInfo *modeInfo, } mode->mode.id = FakeClientID(0); - if (!AddResource (mode->mode.id, RRModeType, (pointer) mode)) - return NULL; + if (!AddResource(mode->mode.id, RRModeType, (pointer) mode)) { + free(newModes); + return NULL; + } modes = newModes; modes[num_modes++] = mode; -- cgit v1.2.3