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>
This commit is contained in:
parent
6bca0184d1
commit
174ccd8493
|
@ -641,14 +641,16 @@ xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
|
||||||
int i, index;
|
int i, index;
|
||||||
sbusCmapPtr cmap;
|
sbusCmapPtr cmap;
|
||||||
struct fbcmap fbcmap;
|
struct fbcmap fbcmap;
|
||||||
unsigned char *data = malloc(numColors * 3);
|
unsigned char *data;
|
||||||
|
|
||||||
cmap = SBUSCMAPPTR(pScrn->pScreen);
|
cmap = SBUSCMAPPTR(pScrn->pScreen);
|
||||||
if (!cmap)
|
if (!cmap)
|
||||||
return;
|
return;
|
||||||
fbcmap.count = 0;
|
fbcmap.count = 0;
|
||||||
fbcmap.index = indices[0];
|
fbcmap.index = indices[0];
|
||||||
fbcmap.red = data;
|
fbcmap.red = data = malloc(numColors * 3);
|
||||||
|
if (!data)
|
||||||
|
return;
|
||||||
fbcmap.green = data + numColors;
|
fbcmap.green = data + numColors;
|
||||||
fbcmap.blue = fbcmap.green + numColors;
|
fbcmap.blue = fbcmap.green + numColors;
|
||||||
for (i = 0; i < numColors; i++) {
|
for (i = 0; i < numColors; i++) {
|
||||||
|
|
Loading…
Reference in New Issue