composite: use calloc() instead of malloc()
Using calloc() instead of malloc() as preventive measure, so there never can be any hidden bugs or leaks due uninitialized memory. The extra cost of using this compiler intrinsic should be practically impossible to measure - in many cases a good compiler can even deduce if certain areas really don't need to be zero'd (because they're written to right after allocation) and create more efficient machine code. The code pathes in question are pretty cold anyways, so it's probably not worth even thinking about potential extra runtime costs. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
c4c5f03cb7
commit
c6b8b78a29
|
@ -138,7 +138,6 @@ compRedirectWindow(ClientPtr pClient, WindowPtr pWin, int update)
|
||||||
BUG_RETURN_VAL(!pClient, BadMatch);
|
BUG_RETURN_VAL(!pClient, BadMatch);
|
||||||
|
|
||||||
CompWindowPtr cw = GetCompWindow(pWin);
|
CompWindowPtr cw = GetCompWindow(pWin);
|
||||||
CompClientWindowPtr ccw;
|
|
||||||
CompScreenPtr cs = GetCompScreen(pWin->drawable.pScreen);
|
CompScreenPtr cs = GetCompScreen(pWin->drawable.pScreen);
|
||||||
WindowPtr pLayerWin;
|
WindowPtr pLayerWin;
|
||||||
Bool anyMarked = FALSE;
|
Bool anyMarked = FALSE;
|
||||||
|
@ -155,7 +154,7 @@ compRedirectWindow(ClientPtr pClient, WindowPtr pWin, int update)
|
||||||
* Only one Manual update is allowed
|
* Only one Manual update is allowed
|
||||||
*/
|
*/
|
||||||
if (cw && update == CompositeRedirectManual)
|
if (cw && update == CompositeRedirectManual)
|
||||||
for (ccw = cw->clients; ccw; ccw = ccw->next)
|
for (CompClientWindowPtr ccw = cw->clients; ccw; ccw = ccw->next)
|
||||||
if (ccw->update == CompositeRedirectManual)
|
if (ccw->update == CompositeRedirectManual)
|
||||||
return BadAccess;
|
return BadAccess;
|
||||||
|
|
||||||
|
@ -164,7 +163,7 @@ compRedirectWindow(ClientPtr pClient, WindowPtr pWin, int update)
|
||||||
* The client *could* allocate multiple, but while supported,
|
* The client *could* allocate multiple, but while supported,
|
||||||
* it is not expected to be common
|
* it is not expected to be common
|
||||||
*/
|
*/
|
||||||
ccw = malloc(sizeof(CompClientWindowRec));
|
CompClientWindowPtr ccw = calloc(1, sizeof(CompClientWindowRec));
|
||||||
if (!ccw)
|
if (!ccw)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
ccw->id = FakeClientID(pClient->index);
|
ccw->id = FakeClientID(pClient->index);
|
||||||
|
@ -173,7 +172,7 @@ compRedirectWindow(ClientPtr pClient, WindowPtr pWin, int update)
|
||||||
* Now make sure there's a per-window structure to hang this from
|
* Now make sure there's a per-window structure to hang this from
|
||||||
*/
|
*/
|
||||||
if (!cw) {
|
if (!cw) {
|
||||||
cw = malloc(sizeof(CompWindowRec));
|
cw = calloc(1, sizeof(CompWindowRec));
|
||||||
if (!cw) {
|
if (!cw) {
|
||||||
free(ccw);
|
free(ccw);
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
@ -348,14 +347,13 @@ int
|
||||||
compRedirectSubwindows(ClientPtr pClient, WindowPtr pWin, int update)
|
compRedirectSubwindows(ClientPtr pClient, WindowPtr pWin, int update)
|
||||||
{
|
{
|
||||||
CompSubwindowsPtr csw = GetCompSubwindows(pWin);
|
CompSubwindowsPtr csw = GetCompSubwindows(pWin);
|
||||||
CompClientWindowPtr ccw;
|
|
||||||
WindowPtr pChild;
|
WindowPtr pChild;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only one Manual update is allowed
|
* Only one Manual update is allowed
|
||||||
*/
|
*/
|
||||||
if (csw && update == CompositeRedirectManual)
|
if (csw && update == CompositeRedirectManual)
|
||||||
for (ccw = csw->clients; ccw; ccw = ccw->next)
|
for (CompClientWindowPtr ccw = csw->clients; ccw; ccw = ccw->next)
|
||||||
if (ccw->update == CompositeRedirectManual)
|
if (ccw->update == CompositeRedirectManual)
|
||||||
return BadAccess;
|
return BadAccess;
|
||||||
/*
|
/*
|
||||||
|
@ -363,7 +361,7 @@ compRedirectSubwindows(ClientPtr pClient, WindowPtr pWin, int update)
|
||||||
* The client *could* allocate multiple, but while supported,
|
* The client *could* allocate multiple, but while supported,
|
||||||
* it is not expected to be common
|
* it is not expected to be common
|
||||||
*/
|
*/
|
||||||
ccw = malloc(sizeof(CompClientWindowRec));
|
CompClientWindowPtr ccw = calloc(1, sizeof(CompClientWindowRec));
|
||||||
if (!ccw)
|
if (!ccw)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
ccw->id = FakeClientID(pClient->index);
|
ccw->id = FakeClientID(pClient->index);
|
||||||
|
@ -372,7 +370,7 @@ compRedirectSubwindows(ClientPtr pClient, WindowPtr pWin, int update)
|
||||||
* Now make sure there's a per-window structure to hang this from
|
* Now make sure there's a per-window structure to hang this from
|
||||||
*/
|
*/
|
||||||
if (!csw) {
|
if (!csw) {
|
||||||
csw = malloc(sizeof(CompSubwindowsRec));
|
csw = calloc(1, sizeof(CompSubwindowsRec));
|
||||||
if (!csw) {
|
if (!csw) {
|
||||||
free(ccw);
|
free(ccw);
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
|
@ -700,7 +700,7 @@ PanoramiXCompositeNameWindowPixmap(ClientPtr client)
|
||||||
|
|
||||||
LEGAL_NEW_RESOURCE(stuff->pixmap, client);
|
LEGAL_NEW_RESOURCE(stuff->pixmap, client);
|
||||||
|
|
||||||
if (!(newPix = malloc(sizeof(PanoramiXRes))))
|
if (!(newPix = calloc(1, sizeof(PanoramiXRes))))
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
newPix->type = XRT_PIXMAP;
|
newPix->type = XRT_PIXMAP;
|
||||||
|
@ -769,7 +769,7 @@ PanoramiXCompositeGetOverlayWindow(ClientPtr client)
|
||||||
|
|
||||||
cs = GetCompScreen(screenInfo.screens[0]);
|
cs = GetCompScreen(screenInfo.screens[0]);
|
||||||
if (!cs->pOverlayWin) {
|
if (!cs->pOverlayWin) {
|
||||||
if (!(overlayWin = malloc(sizeof(PanoramiXRes))))
|
if (!(overlayWin = calloc(1, sizeof(PanoramiXRes))))
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
overlayWin->type = XRT_WINDOW;
|
overlayWin->type = XRT_WINDOW;
|
||||||
|
|
|
@ -331,8 +331,6 @@ compAddAlternateVisuals(ScreenPtr pScreen, CompScreenPtr cs)
|
||||||
Bool
|
Bool
|
||||||
compScreenInit(ScreenPtr pScreen)
|
compScreenInit(ScreenPtr pScreen)
|
||||||
{
|
{
|
||||||
CompScreenPtr cs;
|
|
||||||
|
|
||||||
if (!dixRegisterPrivateKey(&CompScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
|
if (!dixRegisterPrivateKey(&CompScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!dixRegisterPrivateKey(&CompWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
|
if (!dixRegisterPrivateKey(&CompWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
|
||||||
|
@ -342,7 +340,7 @@ compScreenInit(ScreenPtr pScreen)
|
||||||
|
|
||||||
if (GetCompScreen(pScreen))
|
if (GetCompScreen(pScreen))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
cs = (CompScreenPtr) malloc(sizeof(CompScreenRec));
|
CompScreenPtr cs = calloc(1, sizeof(CompScreenRec));
|
||||||
if (!cs)
|
if (!cs)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
|
|
@ -96,9 +96,7 @@ CompOverlayClientPtr
|
||||||
compCreateOverlayClient(ScreenPtr pScreen, ClientPtr pClient)
|
compCreateOverlayClient(ScreenPtr pScreen, ClientPtr pClient)
|
||||||
{
|
{
|
||||||
CompScreenPtr cs = GetCompScreen(pScreen);
|
CompScreenPtr cs = GetCompScreen(pScreen);
|
||||||
CompOverlayClientPtr pOc;
|
CompOverlayClientPtr pOc = calloc(1, sizeof(CompOverlayClientRec));
|
||||||
|
|
||||||
pOc = (CompOverlayClientPtr) malloc(sizeof(CompOverlayClientRec));
|
|
||||||
if (pOc == NULL)
|
if (pOc == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue