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

Marek Chalupa mchqwerty at gmail.com
Wed Nov 26 06:33:16 PST 2014


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>
> ---
>  src/clipboard.c     | 5 +++--
>  src/screenshooter.c | 9 ++-------
>  2 files changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/src/clipboard.c b/src/clipboard.c
> index 5a3a02d..dbd8c9b 100644
> --- a/src/clipboard.c
> +++ b/src/clipboard.c
> @@ -214,9 +214,10 @@ clipboard_client_create(struct clipboard_source
> *source, int fd)
>         struct wl_event_loop *loop =
>                 wl_display_get_event_loop(seat->compositor->wl_display);
>
> -       client = malloc(sizeof *client);
> +       client = zalloc(sizeof *client);
> +       if (client == NULL)
> +               return;
>
> -       client->offset = 0;
>         client->source = source;
>         source->refcount++;
>         client->event_source =
> diff --git a/src/screenshooter.c b/src/screenshooter.c
> index cafbf10..6246cda 100644
> --- a/src/screenshooter.c
> +++ b/src/screenshooter.c
> @@ -481,7 +481,7 @@ weston_recorder_create(struct weston_output *output,
> const char *filename)
>
>         do_yflip = !!(compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP);
>
> -       recorder = malloc(sizeof *recorder);
> +       recorder = zalloc(sizeof *recorder);
>         if (recorder == NULL) {
>                 weston_log("%s: out of memory\n", __func__);
>                 return;
> @@ -491,9 +491,6 @@ weston_recorder_create(struct weston_output *output,
> const char *filename)
>         size = stride * 4 * output->current_mode->height;
>         recorder->frame = zalloc(size);
>         recorder->rect = malloc(size);
> -       recorder->total = 0;
> -       recorder->count = 0;
> -       recorder->destroying = 0;
>         recorder->output = output;
>
>         if ((recorder->frame == NULL) || (recorder->rect == NULL)) {
> @@ -502,9 +499,7 @@ weston_recorder_create(struct weston_output *output,
> const char *filename)
>                 return;
>         }
>
> -       if (do_yflip)
> -               recorder->tmpbuf = NULL;
> -       else
> +       if (!do_yflip)
>                 recorder->tmpbuf = malloc(size);
>

Here you don't check the malloc's result. Also in weston_recorder_destroy
there's no check that tmpbuf was allocated before freeing that memory.


>
>         header.magic = WCAP_HEADER_MAGIC;
> --
> 1.9.1
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>

Thanks,
Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20141126/83ad96d2/attachment.html>


More information about the wayland-devel mailing list