exa: 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 19:15:48 +02:00
parent c6b8b78a29
commit 28e8a3c475
2 changed files with 3 additions and 5 deletions

View File

@ -96,7 +96,7 @@ exaCreatePixmap_mixed(ScreenPtr pScreen, int w, int h, int depth,
pExaPixmap->use_gpu_copy = FALSE; pExaPixmap->use_gpu_copy = FALSE;
if (w == 1 && h == 1) { if (w == 1 && h == 1) {
pExaPixmap->sys_ptr = malloc(paddedWidth); pExaPixmap->sys_ptr = calloc(1, paddedWidth);
/* Set up damage tracking */ /* Set up damage tracking */
pExaPixmap->pDamage = DamageCreate(exaDamageReport_mixed, NULL, pExaPixmap->pDamage = DamageCreate(exaDamageReport_mixed, NULL,

View File

@ -238,7 +238,7 @@ exaOffscreenAlloc(ScreenPtr pScreen, int size, int align,
/* save extra space in new area */ /* save extra space in new area */
if (real_size < area->size) { if (real_size < area->size) {
ExaOffscreenArea *new_area = malloc(sizeof(ExaOffscreenArea)); ExaOffscreenArea *new_area = calloc(1, sizeof(ExaOffscreenArea));
if (!new_area) if (!new_area)
return NULL; return NULL;
@ -634,11 +634,9 @@ Bool
exaOffscreenInit(ScreenPtr pScreen) exaOffscreenInit(ScreenPtr pScreen)
{ {
ExaScreenPriv(pScreen); ExaScreenPriv(pScreen);
ExaOffscreenArea *area;
/* Allocate a big free area */ /* Allocate a big free area */
area = malloc(sizeof(ExaOffscreenArea)); ExaOffscreenArea *area = calloc(1, sizeof(ExaOffscreenArea));
if (!area) if (!area)
return FALSE; return FALSE;