dix: don't free stranger pointers inside AllocARGBCursor

This seems a good convention to follow: if pointers are allocate outside a
given function, then free there as well when a failure occurs.

AllocARGBCursor and its callers were mixing up the freeing of resources and
causing a particular double free inside TileScreenSaver (srcbits and mskbits).

Signed-off-by: Tiago Vignatti <tiago.vignatti@nokia.com>
Reviewed-by: Ander Conselvan de Oliveira <ander.conselvan-de-oliveira@nokia.com>
This commit is contained in:
Tiago Vignatti 2011-04-04 22:31:42 +03:00
parent f603061e94
commit 274dca8f2c
3 changed files with 19 additions and 10 deletions

View File

@ -241,11 +241,8 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
*ppCurs = NULL;
pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1);
if (!pCurs)
{
free(psrcbits);
free(pmaskbits);
return BadAlloc;
}
bits = (CursorBitsPtr)((char *)pCurs + CURSOR_REC_SIZE);
dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR);
dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS)

View File

@ -2976,11 +2976,17 @@ ProcCreateCursor (ClientPtr client)
&pCursor, client, stuff->cid);
if (rc != Success)
return rc;
if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
return BadAlloc;
goto bail;
if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) {
rc = BadAlloc;
goto bail;
}
return Success;
bail:
free(srcbits);
free(mskbits);
return rc;
}
int

View File

@ -1705,11 +1705,17 @@ ProcRenderCreateCursor (ClientPtr client)
GetColor(twocolor[1], 0),
&pCursor, client, stuff->cid);
if (rc != Success)
return rc;
if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
return BadAlloc;
goto bail;
if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) {
rc = BadAlloc;
goto bail;
}
return Success;
bail:
free(srcbits);
free(mskbits);
return rc;
}
static int