diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-02-10 10:24:59 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-04-24 14:22:36 -0700 |
commit | 174ccd84931ece5a92a09c4a1d6a47e0958ebf7e (patch) | |
tree | c1e1e55feb46f82bbe99454cee2e7ed25fa0d37b /hw/xfree86/common | |
parent | 6bca0184d167388cd417d113031317990489987d (diff) |
xf86SbusCmapLoadPalette: Delay malloc until needed, avoiding leak on error
Reported with other leaks found by cppcheck in bugzilla #50281
https://bugs.freedesktop.org/show_bug.cgi?id=50281
V2: check for malloc failure
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'hw/xfree86/common')
-rw-r--r-- | hw/xfree86/common/xf86sbusBus.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c index b6a6b94b3..07eb71ed8 100644 --- a/hw/xfree86/common/xf86sbusBus.c +++ b/hw/xfree86/common/xf86sbusBus.c @@ -641,14 +641,16 @@ xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, int i, index; sbusCmapPtr cmap; struct fbcmap fbcmap; - unsigned char *data = malloc(numColors * 3); + unsigned char *data; cmap = SBUSCMAPPTR(pScrn->pScreen); if (!cmap) return; fbcmap.count = 0; fbcmap.index = indices[0]; - fbcmap.red = data; + fbcmap.red = data = malloc(numColors * 3); + if (!data) + return; fbcmap.green = data + numColors; fbcmap.blue = fbcmap.green + numColors; for (i = 0; i < numColors; i++) { |