Xext: 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:
Enrico Weigelt, metux IT consult 2025-04-10 18:43:08 +02:00
parent 45d7b62d95
commit c96901a85a
18 changed files with 49 additions and 62 deletions

View File

@ -145,10 +145,9 @@ ProcDPMSSelectInput(register ClientPtr client)
} }
/* build the entry */ /* build the entry */
pNewEvent = (DPMSEventPtr)malloc(sizeof(DPMSEventRec)); pNewEvent = calloc(1, sizeof(DPMSEventRec));
if (!pNewEvent) if (!pNewEvent)
return BadAlloc; return BadAlloc;
pNewEvent->next = 0;
pNewEvent->client = client; pNewEvent->client = client;
pNewEvent->mask = stuff->eventMask; pNewEvent->mask = stuff->eventMask;
/* /*
@ -164,7 +163,7 @@ ProcDPMSSelectInput(register ClientPtr client)
* of clients selecting input * of clients selecting input
*/ */
if (i != Success || !pHead) { if (i != Success || !pHead) {
pHead = (DPMSEventPtr *)malloc(sizeof(DPMSEventPtr)); pHead = calloc(1, sizeof(DPMSEventPtr));
if (!pHead || if (!pHead ||
!AddResource(eventResource, DPMSEventType, (void *)pHead)) { !AddResource(eventResource, DPMSEventType, (void *)pHead)) {
FreeResource(clientResource, X11_RESTYPE_NONE); FreeResource(clientResource, X11_RESTYPE_NONE);

View File

@ -39,7 +39,7 @@ ht_create(int keySize,
{ {
int c; int c;
int numBuckets; int numBuckets;
HashTable ht = malloc(sizeof(struct HashTableRec)); HashTable ht = calloc(1, sizeof(struct HashTableRec));
if (!ht) { if (!ht) {
return NULL; return NULL;
@ -127,7 +127,7 @@ ht_add(HashTable ht, const void *key)
if (!elem) { if (!elem) {
goto outOfMemory; goto outOfMemory;
} }
elem->key = malloc(ht->keySize); elem->key = calloc(1, ht->keySize);
if (!elem->key) { if (!elem->key) {
goto outOfMemory; goto outOfMemory;
} }

View File

@ -368,7 +368,7 @@ XineramaRegisterConnectionBlockCallback(void (*func) (void))
{ {
XineramaConnectionCallbackList *newlist; XineramaConnectionCallbackList *newlist;
if (!(newlist = malloc(sizeof(XineramaConnectionCallbackList)))) if (!(newlist = calloc(1, sizeof(XineramaConnectionCallbackList))))
return FALSE; return FALSE;
newlist->next = ConnectionCallbackList; newlist->next = ConnectionCallbackList;
@ -439,7 +439,6 @@ PanoramiXExtensionInit(void)
Bool success = FALSE; Bool success = FALSE;
ExtensionEntry *extEntry; ExtensionEntry *extEntry;
ScreenPtr pScreen = screenInfo.screens[0]; ScreenPtr pScreen = screenInfo.screens[0];
PanoramiXScreenPtr pScreenPriv;
if (noPanoramiXExtension) if (noPanoramiXExtension)
return; return;
@ -476,7 +475,7 @@ PanoramiXExtensionInit(void)
FOR_NSCREENS_BACKWARD(i) { FOR_NSCREENS_BACKWARD(i) {
pScreen = screenInfo.screens[i]; pScreen = screenInfo.screens[i];
pScreenPriv = malloc(sizeof(PanoramiXScreenRec)); PanoramiXScreenPtr pScreenPriv = calloc(1, sizeof(PanoramiXScreenRec));
dixSetPrivate(&pScreen->devPrivates, PanoramiXScreenKey, dixSetPrivate(&pScreen->devPrivates, PanoramiXScreenKey,
pScreenPriv); pScreenPriv);
if (!pScreenPriv) { if (!pScreenPriv) {

View File

@ -117,7 +117,7 @@ PanoramiXCreateWindow(ClientPtr client)
} }
} }
if (!(newWin = malloc(sizeof(PanoramiXRes)))) if (!(newWin = calloc(1, sizeof(PanoramiXRes))))
return BadAlloc; return BadAlloc;
newWin->type = XRT_WINDOW; newWin->type = XRT_WINDOW;
@ -694,7 +694,7 @@ PanoramiXCreatePixmap(ClientPtr client)
if (result != Success) if (result != Success)
return (result == BadValue) ? BadDrawable : result; return (result == BadValue) ? BadDrawable : result;
if (!(newPix = malloc(sizeof(PanoramiXRes)))) if (!(newPix = calloc(1, sizeof(PanoramiXRes))))
return BadAlloc; return BadAlloc;
newPix->type = XRT_PIXMAP; newPix->type = XRT_PIXMAP;
@ -801,7 +801,7 @@ PanoramiXCreateGC(ClientPtr client)
} }
} }
if (!(newGC = malloc(sizeof(PanoramiXRes)))) if (!(newGC = calloc(1, sizeof(PanoramiXRes))))
return BadAlloc; return BadAlloc;
newGC->type = XRT_GC; newGC->type = XRT_GC;
@ -2289,7 +2289,7 @@ PanoramiXCreateColormap(ClientPtr client)
if (result != Success) if (result != Success)
return result; return result;
if (!(newCmap = malloc(sizeof(PanoramiXRes)))) if (!(newCmap = calloc(1, sizeof(PanoramiXRes))))
return BadAlloc; return BadAlloc;
newCmap->type = XRT_COLORMAP; newCmap->type = XRT_COLORMAP;
@ -2361,7 +2361,7 @@ PanoramiXCopyColormapAndFree(ClientPtr client)
if (result != Success) if (result != Success)
return result; return result;
if (!(newCmap = malloc(sizeof(PanoramiXRes)))) if (!(newCmap = calloc(1, sizeof(PanoramiXRes))))
return BadAlloc; return BadAlloc;
newCmap->type = XRT_COLORMAP; newCmap->type = XRT_COLORMAP;

View File

@ -1217,7 +1217,7 @@ ProcScreenSaverSuspend(ClientPtr client)
* to the record, so the screensaver will be re-enabled and the record freed * to the record, so the screensaver will be re-enabled and the record freed
* if the client disconnects without reenabling it first. * if the client disconnects without reenabling it first.
*/ */
this = malloc(sizeof(ScreenSaverSuspensionRec)); this = calloc(1, sizeof(ScreenSaverSuspensionRec));
if (!this) if (!this)
return BadAlloc; return BadAlloc;

View File

@ -385,7 +385,7 @@ SecurityEventSelectForAuthorization(SecurityAuthorizationPtr pAuth,
} }
} }
pEventClient = malloc(sizeof(OtherClients)); pEventClient = calloc(1, sizeof(OtherClients));
if (!pEventClient) if (!pEventClient)
return BadAlloc; return BadAlloc;
pEventClient->mask = mask; pEventClient->mask = mask;
@ -406,7 +406,6 @@ ProcSecurityGenerateAuthorization(ClientPtr client)
REQUEST(xSecurityGenerateAuthorizationReq); REQUEST(xSecurityGenerateAuthorizationReq);
int len; /* request length in CARD32s */ int len; /* request length in CARD32s */
Bool removeAuth = FALSE; /* if bailout, call RemoveAuthorization? */ Bool removeAuth = FALSE; /* if bailout, call RemoveAuthorization? */
SecurityAuthorizationPtr pAuth = NULL; /* auth we are creating */
int err; /* error to return from this function */ int err; /* error to return from this function */
XID authId; /* authorization ID assigned by os layer */ XID authId; /* authorization ID assigned by os layer */
xSecurityGenerateAuthorizationReply rep; /* reply struct */ xSecurityGenerateAuthorizationReply rep; /* reply struct */
@ -493,8 +492,7 @@ ProcSecurityGenerateAuthorization(ClientPtr client)
stuff->nbytesAuthData, protodata, stuff->nbytesAuthData, protodata,
&authdata_len, &pAuthdata); &authdata_len, &pAuthdata);
if ((XID) ~0L == authId) { if ((XID) ~0L == authId) {
err = SecurityErrorBase + XSecurityBadAuthorizationProtocol; return SecurityErrorBase + XSecurityBadAuthorizationProtocol;
goto bailout;
} }
/* now that we've added the auth, remember to remove it if we have to /* now that we've added the auth, remember to remove it if we have to
@ -504,7 +502,7 @@ ProcSecurityGenerateAuthorization(ClientPtr client)
/* associate additional information with this auth ID */ /* associate additional information with this auth ID */
pAuth = malloc(sizeof(SecurityAuthorizationRec)); SecurityAuthorizationPtr pAuth = calloc(1, sizeof(SecurityAuthorizationRec));
if (!pAuth) { if (!pAuth) {
err = BadAlloc; err = BadAlloc;
goto bailout; goto bailout;

View File

@ -752,7 +752,7 @@ ProcShapeSelectInput(ClientPtr client)
} }
/* build the entry */ /* build the entry */
pNewShapeEvent = malloc(sizeof(ShapeEventRec)); pNewShapeEvent = calloc(1, sizeof(ShapeEventRec));
if (!pNewShapeEvent) if (!pNewShapeEvent)
return BadAlloc; return BadAlloc;
pNewShapeEvent->next = 0; pNewShapeEvent->next = 0;
@ -773,7 +773,7 @@ ProcShapeSelectInput(ClientPtr client)
* done through the resource database. * done through the resource database.
*/ */
if (!pHead) { if (!pHead) {
pHead = malloc(sizeof(ShapeEventPtr)); pHead = calloc(1, sizeof(ShapeEventPtr));
if (!pHead || if (!pHead ||
!AddResource(pWin->drawable.id, ShapeEventType, !AddResource(pWin->drawable.id, ShapeEventType,
(void *) pHead)) { (void *) pHead)) {
@ -962,7 +962,7 @@ ProcShapeGetRectangles(ClientPtr client)
} }
if (!region) { if (!region) {
nrects = 1; nrects = 1;
rects = malloc(sizeof(xRectangle)); rects = calloc(1, sizeof(xRectangle));
if (!rects) if (!rects)
return BadAlloc; return BadAlloc;
switch (stuff->kind) { switch (stuff->kind) {

View File

@ -367,7 +367,7 @@ ProcShmAttach(ClientPtr client)
shmdesc->refcnt++; shmdesc->refcnt++;
} }
else { else {
shmdesc = malloc(sizeof(ShmDescRec)); shmdesc = calloc(1, sizeof(ShmDescRec));
if (!shmdesc) if (!shmdesc)
return BadAlloc; return BadAlloc;
#ifdef SHM_FD_PASSING #ifdef SHM_FD_PASSING
@ -756,7 +756,6 @@ static int
ProcPanoramiXShmGetImage(ClientPtr client) ProcPanoramiXShmGetImage(ClientPtr client)
{ {
PanoramiXRes *draw; PanoramiXRes *draw;
DrawablePtr *drawables;
DrawablePtr pDraw; DrawablePtr pDraw;
xShmGetImageReply xgi; xShmGetImageReply xgi;
ShmDescPtr shmdesc; ShmDescPtr shmdesc;
@ -831,7 +830,7 @@ ProcPanoramiXShmGetImage(ClientPtr client)
VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client);
drawables = calloc(PanoramiXNumScreens, sizeof(DrawablePtr)); DrawablePtr *drawables = calloc(PanoramiXNumScreens, sizeof(DrawablePtr));
if (!drawables) if (!drawables)
return BadAlloc; return BadAlloc;
@ -951,7 +950,7 @@ ProcPanoramiXShmCreatePixmap(ClientPtr client)
VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client); VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
if (!(newPix = malloc(sizeof(PanoramiXRes)))) if (!(newPix = calloc(1, sizeof(PanoramiXRes))))
return BadAlloc; return BadAlloc;
newPix->type = XRT_PIXMAP; newPix->type = XRT_PIXMAP;
@ -1144,7 +1143,7 @@ ProcShmAttachFd(ClientPtr client)
return BadMatch; return BadMatch;
} }
shmdesc = malloc(sizeof(ShmDescRec)); shmdesc = calloc(1, sizeof(ShmDescRec));
if (!shmdesc) { if (!shmdesc) {
close(fd); close(fd);
return BadAlloc; return BadAlloc;
@ -1261,7 +1260,7 @@ ProcShmCreateSegment(ClientPtr client)
close(fd); close(fd);
return BadAlloc; return BadAlloc;
} }
shmdesc = malloc(sizeof(ShmDescRec)); shmdesc = calloc(1, sizeof(ShmDescRec));
if (!shmdesc) { if (!shmdesc) {
close(fd); close(fd);
return BadAlloc; return BadAlloc;

View File

@ -72,7 +72,7 @@ ClientSleepUntil(ClientPtr client,
TimeStamp *revive, TimeStamp *revive,
void (*notifyFunc) (ClientPtr, void *), void *closure) void (*notifyFunc) (ClientPtr, void *), void *closure)
{ {
SertafiedPtr pRequest, pReq, pPrev; SertafiedPtr pReq, pPrev;
if (SertafiedGeneration != serverGeneration) { if (SertafiedGeneration != serverGeneration) {
SertafiedResType = CreateNewResourceType(SertafiedDelete, SertafiedResType = CreateNewResourceType(SertafiedDelete,
@ -82,7 +82,8 @@ ClientSleepUntil(ClientPtr client,
SertafiedGeneration = serverGeneration; SertafiedGeneration = serverGeneration;
BlockHandlerRegistered = FALSE; BlockHandlerRegistered = FALSE;
} }
pRequest = malloc(sizeof(SertafiedRec));
SertafiedPtr pRequest = calloc(1, sizeof(SertafiedRec));
if (!pRequest) if (!pRequest)
return FALSE; return FALSE;
pRequest->pClient = client; pRequest->pClient = client;

View File

@ -764,8 +764,6 @@ SyncChangeCounter(SyncCounter * pCounter, int64_t newval)
static Bool static Bool
SyncEventSelectForAlarm(SyncAlarm * pAlarm, ClientPtr client, Bool wantevents) SyncEventSelectForAlarm(SyncAlarm * pAlarm, ClientPtr client, Bool wantevents)
{ {
SyncAlarmClientList *pClients;
if (client == pAlarm->client) { /* alarm owner */ if (client == pAlarm->client) { /* alarm owner */
pAlarm->events = wantevents; pAlarm->events = wantevents;
return Success; return Success;
@ -773,7 +771,8 @@ SyncEventSelectForAlarm(SyncAlarm * pAlarm, ClientPtr client, Bool wantevents)
/* see if the client is already on the list (has events selected) */ /* see if the client is already on the list (has events selected) */
for (pClients = pAlarm->pEventClients; pClients; pClients = pClients->next) { for (SyncAlarmClientList *pClients = pClients = pAlarm->pEventClients;
pClients; pClients = pClients->next) {
if (pClients->client == client) { if (pClients->client == client) {
/* client's presence on the list indicates desire for /* client's presence on the list indicates desire for
* events. If the client doesn't want events, remove it * events. If the client doesn't want events, remove it
@ -799,7 +798,7 @@ SyncEventSelectForAlarm(SyncAlarm * pAlarm, ClientPtr client, Bool wantevents)
/* add new client to pAlarm->pEventClients */ /* add new client to pAlarm->pEventClients */
pClients = malloc(sizeof(SyncAlarmClientList)); SyncAlarmClientList *pClients = calloc(1, sizeof(SyncAlarmClientList));
if (!pClients) if (!pClients)
return BadAlloc; return BadAlloc;
@ -934,7 +933,7 @@ SyncCreate(ClientPtr client, XID id, unsigned char type)
switch (type) { switch (type) {
case SYNC_COUNTER: case SYNC_COUNTER:
pSync = malloc(sizeof(SyncCounter)); pSync = calloc(1, sizeof(SyncCounter));
resType = RTCounter; resType = RTCounter;
break; break;
case SYNC_FENCE: case SYNC_FENCE:
@ -1030,9 +1029,7 @@ SyncCreateSystemCounter(const char *name,
SyncCounter *pCounter = SyncCreateCounter(NULL, FakeClientID(0), initial); SyncCounter *pCounter = SyncCreateCounter(NULL, FakeClientID(0), initial);
if (pCounter) { if (pCounter) {
SysCounterInfo *psci; SysCounterInfo *psci = calloc(1, sizeof(SysCounterInfo));
psci = malloc(sizeof(SysCounterInfo));
if (!psci) { if (!psci) {
FreeResource(pCounter->sync.id, X11_RESTYPE_NONE); FreeResource(pCounter->sync.id, X11_RESTYPE_NONE);
return pCounter; return pCounter;
@ -1311,7 +1308,7 @@ ProcSyncListSystemCounters(ClientPtr client)
} }
if (len) { if (len) {
walklist = list = malloc(len); walklist = list = calloc(1, len);
if (!list) if (!list)
return BadAlloc; return BadAlloc;
} }
@ -1739,7 +1736,7 @@ ProcSyncCreateAlarm(ClientPtr client)
if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue | XSyncCADelta)))) if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue | XSyncCADelta))))
return BadLength; return BadLength;
if (!(pAlarm = malloc(sizeof(SyncAlarm)))) { if (!(pAlarm = calloc(1, sizeof(SyncAlarm)))) {
return BadAlloc; return BadAlloc;
} }

View File

@ -75,9 +75,7 @@ typedef struct {
static DisplayModePtr static DisplayModePtr
VidModeCreateMode(void) VidModeCreateMode(void)
{ {
DisplayModePtr mode; DisplayModePtr mode = calloc(1, sizeof(DisplayModeRec));
mode = malloc(sizeof(DisplayModeRec));
if (mode != NULL) { if (mode != NULL) {
mode->name = ""; mode->name = "";
mode->VScan = 1; /* divides refresh rate. default = 1 */ mode->VScan = 1; /* divides refresh rate. default = 1 */
@ -1636,7 +1634,7 @@ ProcVidModeSetClientVersion(ClientPtr client)
REQUEST_SIZE_MATCH(xXF86VidModeSetClientVersionReq); REQUEST_SIZE_MATCH(xXF86VidModeSetClientVersionReq);
if ((pPriv = VM_GETPRIV(client)) == NULL) { if ((pPriv = VM_GETPRIV(client)) == NULL) {
pPriv = malloc(sizeof(VidModePrivRec)); pPriv = calloc(1, sizeof(VidModePrivRec));
if (!pPriv) if (!pPriv)
return BadAlloc; return BadAlloc;
VM_SETPRIV(client, pPriv); VM_SETPRIV(client, pPriv);

View File

@ -204,7 +204,6 @@ XaceCensorImage(ClientPtr client,
if (nRects > 0) { /* we have something to censor */ if (nRects > 0) { /* we have something to censor */
GCPtr pScratchGC = NULL; GCPtr pScratchGC = NULL;
PixmapPtr pPix = NULL; PixmapPtr pPix = NULL;
xRectangle *pRects = NULL;
Bool failed = FALSE; Bool failed = FALSE;
int depth = 1; int depth = 1;
int bitsPerPixel = 1; int bitsPerPixel = 1;
@ -213,7 +212,7 @@ XaceCensorImage(ClientPtr client,
/* convert region to list-of-rectangles for PolyFillRect */ /* convert region to list-of-rectangles for PolyFillRect */
pRects = malloc(nRects * sizeof(xRectangle)); xRectangle *pRects = calloc(1, nRects * sizeof(xRectangle));
if (!pRects) { if (!pRects) {
failed = TRUE; failed = TRUE;
goto failSafe; goto failSafe;

View File

@ -147,7 +147,6 @@ static ShmDescPtr ShmList = (ShmDescPtr) NULL;
static ShmDescPtr static ShmDescPtr
shmalloc(unsigned int size) shmalloc(unsigned int size)
{ {
ShmDescPtr pDesc;
int shmid; int shmid;
char *addr; char *addr;
@ -165,7 +164,7 @@ shmalloc(unsigned int size)
if (size < 3500) if (size < 3500)
return (ShmDescPtr) NULL; return (ShmDescPtr) NULL;
pDesc = malloc(sizeof(ShmDescRec)); ShmDescPtr pDesc = calloc(1, sizeof(ShmDescRec));
if (!pDesc) if (!pDesc)
return (ShmDescPtr) NULL; return (ShmDescPtr) NULL;

View File

@ -100,7 +100,7 @@ typedef struct {
static void * static void *
AddFragment(struct xorg_list *frags, int bytes) AddFragment(struct xorg_list *frags, int bytes)
{ {
FragmentList *f = malloc(sizeof(FragmentList) + bytes); FragmentList *f = calloc(1, sizeof(FragmentList) + bytes);
if (!f) { if (!f) {
return NULL; return NULL;
} else { } else {

View File

@ -55,7 +55,7 @@ int selinuxEnforcingState = SELINUX_MODE_DEFAULT;
static char * static char *
SELinuxCopyContext(char *ptr, unsigned len) SELinuxCopyContext(char *ptr, unsigned len)
{ {
char *copy = malloc(len + 1); char *copy = calloc(1, len + 1);
if (!copy) if (!copy)
return NULL; return NULL;

View File

@ -992,7 +992,7 @@ ProcXvQueryImageAttributes(ClientPtr client)
num_planes = pImage->num_planes; num_planes = pImage->num_planes;
if (!(offsets = malloc(num_planes << 3))) if (!(offsets = calloc(1, num_planes << 3)))
return BadAlloc; return BadAlloc;
pitches = offsets + num_planes; pitches = offsets + num_planes;
@ -1745,7 +1745,7 @@ XineramifyXv(void)
/* now create a resource for each port */ /* now create a resource for each port */
for (j = 0; j < refAdapt->nPorts; j++) { for (j = 0; j < refAdapt->nPorts; j++) {
PanoramiXRes *port = malloc(sizeof(PanoramiXRes)); PanoramiXRes *port = calloc(1, sizeof(PanoramiXRes));
if (!port) if (!port)
break; break;

View File

@ -270,8 +270,6 @@ static void XvPixmapDestroy(CallbackListPtr *pcbl, ScreenPtr pScreen, PixmapPtr
int int
XvScreenInit(ScreenPtr pScreen) XvScreenInit(ScreenPtr pScreen)
{ {
XvScreenPtr pxvs;
if (XvScreenGeneration != serverGeneration) { if (XvScreenGeneration != serverGeneration) {
if (!CreateResourceTypes()) { if (!CreateResourceTypes()) {
ErrorF("XvScreenInit: Unable to allocate resource types\n"); ErrorF("XvScreenInit: Unable to allocate resource types\n");
@ -292,7 +290,7 @@ XvScreenInit(ScreenPtr pScreen)
/* ALLOCATE SCREEN PRIVATE RECORD */ /* ALLOCATE SCREEN PRIVATE RECORD */
pxvs = malloc(sizeof(XvScreenRec)); XvScreenPtr pxvs = calloc(1, sizeof(XvScreenRec));
if (!pxvs) { if (!pxvs) {
ErrorF("XvScreenInit: Unable to allocate screen private structure\n"); ErrorF("XvScreenInit: Unable to allocate screen private structure\n");
return BadAlloc; return BadAlloc;
@ -777,7 +775,7 @@ XvdiSelectVideoNotify(ClientPtr client, DrawablePtr pDraw, BOOL onoff)
WILL BE DELETED WHEN THE DRAWABLE IS DESTROYED */ WILL BE DELETED WHEN THE DRAWABLE IS DESTROYED */
if (!pn) { if (!pn) {
if (!(tpn = malloc(sizeof(XvVideoNotifyRec)))) if (!(tpn = calloc(1, sizeof(XvVideoNotifyRec))))
return BadAlloc; return BadAlloc;
tpn->next = NULL; tpn->next = NULL;
tpn->client = NULL; tpn->client = NULL;
@ -813,7 +811,7 @@ XvdiSelectVideoNotify(ClientPtr client, DrawablePtr pDraw, BOOL onoff)
tpn = fpn; tpn = fpn;
} }
else { else {
if (!(tpn = malloc(sizeof(XvVideoNotifyRec)))) if (!(tpn = calloc(1, sizeof(XvVideoNotifyRec))))
return BadAlloc; return BadAlloc;
tpn->next = pn->next; tpn->next = pn->next;
pn->next = tpn; pn->next = tpn;
@ -867,7 +865,7 @@ XvdiSelectPortNotify(ClientPtr client, XvPortPtr pPort, BOOL onoff)
CREATE A NEW ONE AND ADD IT TO THE BEGINNING OF THE LIST */ CREATE A NEW ONE AND ADD IT TO THE BEGINNING OF THE LIST */
if (!tpn) { if (!tpn) {
if (!(tpn = malloc(sizeof(XvPortNotifyRec)))) if (!(tpn = calloc(1, sizeof(XvPortNotifyRec))))
return BadAlloc; return BadAlloc;
tpn->next = pPort->pNotify; tpn->next = pPort->pNotify;
pPort->pNotify = tpn; pPort->pNotify = tpn;

View File

@ -233,7 +233,7 @@ ProcXvMCCreateContext(ClientPtr client)
(stuff->height > surface->max_height)) (stuff->height > surface->max_height))
return BadValue; return BadValue;
if (!(pContext = malloc(sizeof(XvMCContextRec)))) { if (!(pContext = calloc(1, sizeof(XvMCContextRec)))) {
return BadAlloc; return BadAlloc;
} }
@ -315,7 +315,7 @@ ProcXvMCCreateSurface(ClientPtr client)
pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen); pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen);
if (!(pSurface = malloc(sizeof(XvMCSurfaceRec)))) if (!(pSurface = calloc(1, sizeof(XvMCSurfaceRec))))
return BadAlloc; return BadAlloc;
pSurface->surface_id = stuff->surface_id; pSurface->surface_id = stuff->surface_id;
@ -428,7 +428,7 @@ ProcXvMCCreateSubpicture(ClientPtr client)
(stuff->height > surface->subpicture_max_height)) (stuff->height > surface->subpicture_max_height))
return BadValue; return BadValue;
if (!(pSubpicture = malloc(sizeof(XvMCSubpictureRec)))) if (!(pSubpicture = calloc(1, sizeof(XvMCSubpictureRec))))
return BadAlloc; return BadAlloc;
pSubpicture->subpicture_id = stuff->subpicture_id; pSubpicture->subpicture_id = stuff->subpicture_id;
@ -749,7 +749,7 @@ XvMCScreenInit(ScreenPtr pScreen, int num, XvMCAdaptorPtr pAdapt)
if (!dixRegisterPrivateKey(&XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) if (!dixRegisterPrivateKey(&XvMCScreenKeyRec, PRIVATE_SCREEN, 0))
return BadAlloc; return BadAlloc;
if (!(pScreenPriv = malloc(sizeof(XvMCScreenRec)))) if (!(pScreenPriv = calloc(1, sizeof(XvMCScreenRec))))
return BadAlloc; return BadAlloc;
dixSetPrivate(&pScreen->devPrivates, XvMCScreenKey, pScreenPriv); dixSetPrivate(&pScreen->devPrivates, XvMCScreenKey, pScreenPriv);