[PATCH 1/3] Use zalloc rather than malloc and manually setting members to 0

Bryce Harrington bryce at osg.samsung.com
Wed Nov 26 13:49:17 PST 2014


On Wed, Nov 26, 2014 at 03:33:16PM +0100, Marek Chalupa wrote:
> On 21 November 2014 at 07:21, Bryce Harrington <bryce at osg.samsung.com>
> wrote:
> 
> > Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> >
> > -       if (do_yflip)
> > -               recorder->tmpbuf = NULL;
> > -       else
> > +       if (!do_yflip)
> >                 recorder->tmpbuf = malloc(size);
> >
> 
> Here you don't check the malloc's result.

Good point.  The original code didn't either, but
weston_recorder_frame_notify() looks like it assumes tmpbuf is valid and
would crash there otherwise.  I can add this.

> Also in weston_recorder_destroy
> there's no check that tmpbuf was allocated before freeing that memory.

Actually it's unnecessary to check for NULL before calling free().
free(NULL) is a no-op as per `man 3 malloc`.

Thanks for the review!

Bryce



More information about the wayland-devel mailing list