xwayland: 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
5377ee4d81
commit
dda1bb1e95
|
@ -168,7 +168,6 @@ xwl_glamor_gbm_create_pixmap_for_bo(ScreenPtr screen, struct gbm_bo *bo,
|
||||||
Bool implicit_modifier)
|
Bool implicit_modifier)
|
||||||
{
|
{
|
||||||
PixmapPtr pixmap;
|
PixmapPtr pixmap;
|
||||||
struct xwl_pixmap *xwl_pixmap;
|
|
||||||
struct xwl_screen *xwl_screen = xwl_screen_get(screen);
|
struct xwl_screen *xwl_screen = xwl_screen_get(screen);
|
||||||
#ifdef GBM_BO_FD_FOR_PLANE
|
#ifdef GBM_BO_FD_FOR_PLANE
|
||||||
struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
|
struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
|
||||||
|
@ -220,7 +219,7 @@ xwl_glamor_gbm_create_pixmap_for_bo(ScreenPtr screen, struct gbm_bo *bo,
|
||||||
for (plane = 0; plane < num_planes; plane++) fds[plane] = -1;
|
for (plane = 0; plane < num_planes; plane++) fds[plane] = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
xwl_pixmap = calloc(1, sizeof(*xwl_pixmap));
|
struct xwl_pixmap *xwl_pixmap = calloc(1, sizeof(struct xwl_pixmap));
|
||||||
if (xwl_pixmap == NULL)
|
if (xwl_pixmap == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -719,7 +718,6 @@ xwl_dri3_open_client(ClientPtr client,
|
||||||
{
|
{
|
||||||
struct xwl_screen *xwl_screen = xwl_screen_get(screen);
|
struct xwl_screen *xwl_screen = xwl_screen_get(screen);
|
||||||
struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
|
struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
|
||||||
struct xwl_auth_state *state;
|
|
||||||
drm_magic_t magic;
|
drm_magic_t magic;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
@ -731,7 +729,7 @@ xwl_dri3_open_client(ClientPtr client,
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = malloc(sizeof *state);
|
struct xwl_auth_state *state = calloc(1, sizeof(struct xwl_auth_state));
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
|
@ -129,7 +129,6 @@ os_create_anonymous_file(off_t size)
|
||||||
{
|
{
|
||||||
static const char template[] = "/xwayland-shared-XXXXXX";
|
static const char template[] = "/xwayland-shared-XXXXXX";
|
||||||
const char *path;
|
const char *path;
|
||||||
char *name;
|
|
||||||
int fd;
|
int fd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -152,7 +151,7 @@ os_create_anonymous_file(off_t size)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = malloc(strlen(path) + sizeof(template));
|
char *name = calloc(1, strlen(path) + sizeof(template));
|
||||||
if (!name)
|
if (!name)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue