From 28e8a3c475b295e1a3bb99f0eef3e6e8d17e0a5d Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 10 Apr 2025 19:15:48 +0200 Subject: [PATCH] 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 --- exa/exa_mixed.c | 2 +- exa/exa_offscreen.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c index 271e25c08..b15d9ea14 100644 --- a/exa/exa_mixed.c +++ b/exa/exa_mixed.c @@ -96,7 +96,7 @@ exaCreatePixmap_mixed(ScreenPtr pScreen, int w, int h, int depth, pExaPixmap->use_gpu_copy = FALSE; if (w == 1 && h == 1) { - pExaPixmap->sys_ptr = malloc(paddedWidth); + pExaPixmap->sys_ptr = calloc(1, paddedWidth); /* Set up damage tracking */ pExaPixmap->pDamage = DamageCreate(exaDamageReport_mixed, NULL, diff --git a/exa/exa_offscreen.c b/exa/exa_offscreen.c index 37fb624da..3a29732b8 100644 --- a/exa/exa_offscreen.c +++ b/exa/exa_offscreen.c @@ -238,7 +238,7 @@ exaOffscreenAlloc(ScreenPtr pScreen, int size, int align, /* save extra space in new area */ if (real_size < area->size) { - ExaOffscreenArea *new_area = malloc(sizeof(ExaOffscreenArea)); + ExaOffscreenArea *new_area = calloc(1, sizeof(ExaOffscreenArea)); if (!new_area) return NULL; @@ -634,11 +634,9 @@ Bool exaOffscreenInit(ScreenPtr pScreen) { ExaScreenPriv(pScreen); - ExaOffscreenArea *area; /* Allocate a big free area */ - area = malloc(sizeof(ExaOffscreenArea)); - + ExaOffscreenArea *area = calloc(1, sizeof(ExaOffscreenArea)); if (!area) return FALSE;