[PATCH weston] clients: Simplify memory allocation with xzalloc()
Bryce Harrington
bryce at osg.samsung.com
Fri Jul 10 00:17:02 PDT 2015
On Wed, Jul 01, 2015 at 12:18:26PM +0200, Marek Chalupa wrote:
> Reviewed-by: Marek Chalupa <mchqwerty at gmail.com>
Thanks, landed:
remote: I: patch #52362 updated using rev
da9d8fa3e46cc035f94be6441452a7738327ecf0
remote: I: 1 patch(es) updated to state Accepted.
To ssh://git.freedesktop.org/git/wayland/weston
430aee1..da9d8fa master -> master
> On Sat, Jun 20, 2015 at 1:12 AM, Bryce Harrington <bryce at osg.samsung.com>
> wrote:
>
> > It is redundant to check x*alloc's return value for null pointers, since
> > they are guaranteed to either return non-NULL or terminate the program.
> >
> > In cases where we memset the malloc'd memory to 0, we can more
> > efficiently use the xzalloc() routine. zalloc looks for opportunities
> > to return memory chunks that have already been zero'd out, so it can
> > provide better performance.
> >
> > This patch addresses this warning, reported by Denis Denisov:
> >
> > [clients/window.c:1164] -> [clients/window.c:1166]: (warning) Possible
> > null pointer dereference: surface - otherwise it is redundant to check
> > it against null.
> >
> > [clients/window.c:4513] -> [clients/window.c:4514]: (warning) Possible
> > null pointer dereference: surface - otherwise it is redundant to check
> > it against null.
> >
> > Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> > ---
> > clients/window.c | 13 ++-----------
> > 1 file changed, 2 insertions(+), 11 deletions(-)
> >
> > diff --git a/clients/window.c b/clients/window.c
> > index ff4be8c..8e43e18 100644
> > --- a/clients/window.c
> > +++ b/clients/window.c
> > @@ -1162,12 +1162,7 @@ shm_surface_create(struct display *display, struct
> > wl_surface *wl_surface,
> > struct shm_surface *surface;
> > DBG_OBJ(wl_surface, "\n");
> >
> > - surface = xmalloc(sizeof *surface);
> > - memset(surface, 0, sizeof *surface);
> > -
> > - if (!surface)
> > - return NULL;
> > -
> > + surface = xzalloc(sizeof *surface);
> > surface->base.prepare = shm_surface_prepare;
> > surface->base.swap = shm_surface_swap;
> > surface->base.acquire = shm_surface_acquire;
> > @@ -4511,11 +4506,7 @@ surface_create(struct window *window)
> > struct display *display = window->display;
> > struct surface *surface;
> >
> > - surface = xmalloc(sizeof *surface);
> > - memset(surface, 0, sizeof *surface);
> > - if (!surface)
> > - return NULL;
> > -
> > + surface = xzalloc(sizeof *surface);
> > surface->window = window;
> > surface->surface =
> > wl_compositor_create_surface(display->compositor);
> > surface->buffer_scale = 1;
> > --
> > 1.9.1
> >
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> >
More information about the wayland-devel
mailing list