<div dir="ltr"><div>$ git grep calloc\(1, <br><br></div>reveals that there are quite few more places where calloc(1, ...) is used. However, this patch is a good starter.<br><div><br><div>Reviewed-by: Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 21 November 2014 at 07:21, Bryce Harrington <span dir="ltr"><<a href="mailto:bryce@osg.samsung.com" target="_blank">bryce@osg.samsung.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Bryce Harrington <<a href="mailto:bryce@osg.samsung.com">bryce@osg.samsung.com</a>><br>
---<br>
 src/cms-helper.c       |  2 +-<br>
 src/compositor-drm.c   |  4 ++--<br>
 src/compositor-fbdev.c |  6 +++---<br>
 src/compositor-rpi.c   |  6 +++---<br>
 src/compositor.c       | 16 ++++++++--------<br>
 src/gl-renderer.c      | 12 +++++-------<br>
 src/logind-util.c      |  4 ++--<br>
 src/pixman-renderer.c  | 11 ++++++-----<br>
 src/rpi-renderer.c     | 16 ++++++++--------<br>
 src/text-backend.c     | 18 +++++++++++++-----<br>
 src/vaapi-recorder.c   |  4 ++--<br>
 11 files changed, 53 insertions(+), 46 deletions(-)<br>
<br>
diff --git a/src/cms-helper.c b/src/cms-helper.c<br>
index c063c77..b586847 100644<br>
--- a/src/cms-helper.c<br>
+++ b/src/cms-helper.c<br>
@@ -112,7 +112,7 @@ weston_cms_create_profile(const char *filename,<br>
                          void *lcms_profile)<br>
 {<br>
        struct weston_color_profile *p;<br>
-       p = calloc(1, sizeof(struct weston_color_profile));<br>
+       p = zalloc(sizeof(struct weston_color_profile));<br>
        p->filename = strdup(filename);<br>
        p->lcms_handle = lcms_profile;<br>
        return p;<br>
diff --git a/src/compositor-drm.c b/src/compositor-drm.c<br>
index 702bae8..f97c22f 100644<br>
--- a/src/compositor-drm.c<br>
+++ b/src/compositor-drm.c<br>
@@ -348,8 +348,8 @@ drm_fb_get_from_bo(struct gbm_bo *bo,<br>
        if (fb)<br>
                return fb;<br>
<br>
-       fb = calloc(1, sizeof *fb);<br>
-       if (!fb)<br>
+       fb = zalloc(sizeof *fb);<br>
+       if (fb == NULL)<br>
                return NULL;<br>
<br>
        fb->bo = bo;<br>
diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c<br>
index ccc017a..d4f7732 100644<br>
--- a/src/compositor-fbdev.c<br>
+++ b/src/compositor-fbdev.c<br>
@@ -508,8 +508,8 @@ fbdev_output_create(struct fbdev_compositor *compositor,<br>
<br>
        weston_log("Creating fbdev output.\n");<br>
<br>
-       output = calloc(1, sizeof *output);<br>
-       if (!output)<br>
+       output = zalloc(sizeof *output);<br>
+       if (output == NULL)<br>
                return -1;<br>
<br>
        output->compositor = compositor;<br>
@@ -869,7 +869,7 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],<br>
<br>
        weston_log("initializing fbdev backend\n");<br>
<br>
-       compositor = calloc(1, sizeof *compositor);<br>
+       compositor = zalloc(sizeof *compositor);<br>
        if (compositor == NULL)<br>
                return NULL;<br>
<br>
diff --git a/src/compositor-rpi.c b/src/compositor-rpi.c<br>
index c906701..25f3ad4 100644<br>
--- a/src/compositor-rpi.c<br>
+++ b/src/compositor-rpi.c<br>
@@ -289,8 +289,8 @@ rpi_output_create(struct rpi_compositor *compositor, uint32_t transform)<br>
        int ret;<br>
        float mm_width, mm_height;<br>
<br>
-       output = calloc(1, sizeof *output);<br>
-       if (!output)<br>
+       output = zalloc(sizeof *output);<br>
+       if (output == NULL)<br>
                return -1;<br>
<br>
        output->compositor = compositor;<br>
@@ -459,7 +459,7 @@ rpi_compositor_create(struct wl_display *display, int *argc, char *argv[],<br>
<br>
        weston_log("initializing Raspberry Pi backend\n");<br>
<br>
-       compositor = calloc(1, sizeof *compositor);<br>
+       compositor = zalloc(sizeof *compositor);<br>
        if (compositor == NULL)<br>
                return NULL;<br>
<br>
diff --git a/src/compositor.c b/src/compositor.c<br>
index f19c33f..db95901 100644<br>
--- a/src/compositor.c<br>
+++ b/src/compositor.c<br>
@@ -427,7 +427,7 @@ weston_view_create(struct weston_surface *surface)<br>
 {<br>
        struct weston_view *view;<br>
<br>
-       view = calloc(1, sizeof *view);<br>
+       view = zalloc(sizeof *view);<br>
        if (view == NULL)<br>
                return NULL;<br>
<br>
@@ -605,7 +605,7 @@ weston_surface_create(struct weston_compositor *compositor)<br>
 {<br>
        struct weston_surface *surface;<br>
<br>
-       surface = calloc(1, sizeof *surface);<br>
+       surface = zalloc(sizeof *surface);<br>
        if (surface == NULL)<br>
                return NULL;<br>
<br>
@@ -3066,8 +3066,8 @@ weston_subsurface_create(uint32_t id, struct weston_surface *surface,<br>
        struct weston_subsurface *sub;<br>
        struct wl_client *client = wl_resource_get_client(surface->resource);<br>
<br>
-       sub = calloc(1, sizeof *sub);<br>
-       if (!sub)<br>
+       sub = zalloc(sizeof *sub);<br>
+       if (sub == NULL)<br>
                return NULL;<br>
<br>
        wl_list_init(&sub->unused_views);<br>
@@ -3099,8 +3099,8 @@ weston_subsurface_create_for_parent(struct weston_surface *parent)<br>
 {<br>
        struct weston_subsurface *sub;<br>
<br>
-       sub = calloc(1, sizeof *sub);<br>
-       if (!sub)<br>
+       sub = zalloc(sizeof *sub);<br>
+       if (sub == NULL)<br>
                return NULL;<br>
<br>
        weston_subsurface_link_surface(sub, parent);<br>
@@ -3908,8 +3908,8 @@ presentation_feedback(struct wl_client *client,<br>
<br>
        surface = wl_resource_get_user_data(surface_resource);<br>
<br>
-       feedback = calloc(1, sizeof *feedback);<br>
-       if (!feedback)<br>
+       feedback = zalloc(sizeof *feedback);<br>
+       if (feedback == NULL)<br>
                goto err_calloc;<br>
<br>
        feedback->resource = wl_resource_create(client,<br>
diff --git a/src/gl-renderer.c b/src/gl-renderer.c<br>
index 677b43b..0b3f9ba 100644<br>
--- a/src/gl-renderer.c<br>
+++ b/src/gl-renderer.c<br>
@@ -1352,8 +1352,8 @@ gl_renderer_create_surface(struct weston_surface *surface)<br>
        struct gl_surface_state *gs;<br>
        struct gl_renderer *gr = get_renderer(surface->compositor);<br>
<br>
-       gs = calloc(1, sizeof *gs);<br>
-       if (!gs)<br>
+       gs = zalloc(sizeof *gs);<br>
+       if (gs == NULL)<br>
                return -1;<br>
<br>
        /* A buffer is never attached to solid color surfaces, yet<br>
@@ -1755,9 +1755,8 @@ gl_renderer_output_create(struct weston_output *output,<br>
                return -1;<br>
        }<br>
<br>
-       go = calloc(1, sizeof *go);<br>
-<br>
-       if (!go)<br>
+       go = zalloc(sizeof *go);<br>
+       if (go == NULL)<br>
                return -1;<br>
<br>
        go->egl_surface =<br>
@@ -1918,8 +1917,7 @@ gl_renderer_create(struct weston_compositor *ec, EGLNativeDisplayType display,<br>
        struct gl_renderer *gr;<br>
        EGLint major, minor;<br>
<br>
-       gr = calloc(1, sizeof *gr);<br>
-<br>
+       gr = zalloc(sizeof *gr);<br>
        if (gr == NULL)<br>
                return -1;<br>
<br>
diff --git a/src/logind-util.c b/src/logind-util.c<br>
index 6a1b498..554e64d 100644<br>
--- a/src/logind-util.c<br>
+++ b/src/logind-util.c<br>
@@ -834,8 +834,8 @@ weston_logind_connect(struct weston_logind **out,<br>
        char *t;<br>
        int r;<br>
<br>
-       wl = calloc(1, sizeof(*wl));<br>
-       if (!wl) {<br>
+       wl = zalloc(sizeof(*wl));<br>
+       if (wl == NULL) {<br>
                r = -ENOMEM;<br>
                goto err_out;<br>
        }<br>
diff --git a/src/pixman-renderer.c b/src/pixman-renderer.c<br>
index 2c26c3a..530e2ed 100644<br>
--- a/src/pixman-renderer.c<br>
+++ b/src/pixman-renderer.c<br>
@@ -622,8 +622,8 @@ pixman_renderer_create_surface(struct weston_surface *surface)<br>
        struct pixman_surface_state *ps;<br>
        struct pixman_renderer *pr = get_renderer(surface->compositor);<br>
<br>
-       ps = calloc(1, sizeof *ps);<br>
-       if (!ps)<br>
+       ps = zalloc(sizeof *ps);<br>
+       if (ps == NULL)<br>
                return -1;<br>
<br>
        surface->renderer_state = ps;<br>
@@ -701,7 +701,7 @@ pixman_renderer_init(struct weston_compositor *ec)<br>
 {<br>
        struct pixman_renderer *renderer;<br>
<br>
-       renderer = calloc(1, sizeof *renderer);<br>
+       renderer = zalloc(sizeof *renderer);<br>
        if (renderer == NULL)<br>
                return -1;<br>
<br>
@@ -746,10 +746,11 @@ pixman_renderer_output_set_buffer(struct weston_output *output, pixman_image_t *<br>
 WL_EXPORT int<br>
 pixman_renderer_output_create(struct weston_output *output)<br>
 {<br>
-       struct pixman_output_state *po = calloc(1, sizeof *po);<br>
+       struct pixman_output_state *po;<br>
        int w, h;<br>
<br>
-       if (!po)<br>
+       po = zalloc(sizeof *po);<br>
+       if (po == NULL)<br>
                return -1;<br>
<br>
        /* set shadow image transformation */<br>
diff --git a/src/rpi-renderer.c b/src/rpi-renderer.c<br>
index 4d0f522..2feab63 100644<br>
--- a/src/rpi-renderer.c<br>
+++ b/src/rpi-renderer.c<br>
@@ -492,8 +492,8 @@ rpir_surface_create(struct rpi_renderer *renderer)<br>
 {<br>
        struct rpir_surface *surface;<br>
<br>
-       surface = calloc(1, sizeof *surface);<br>
-       if (!surface)<br>
+       surface = zalloc(sizeof *surface);<br>
+       if (surface == NULL)<br>
                return NULL;<br>
<br>
        wl_list_init(&surface->views);<br>
@@ -576,8 +576,8 @@ rpir_view_create(struct rpir_surface *surface)<br>
 {<br>
        struct rpir_view *view;<br>
<br>
-       view = calloc(1, sizeof *view);<br>
-       if (!view)<br>
+       view = zalloc(sizeof *view);<br>
+       if (view == NULL)<br>
                return NULL;<br>
<br>
        view->surface = surface;<br>
@@ -1549,7 +1549,7 @@ rpi_renderer_attach(struct weston_surface *base, struct weston_buffer *buffer)<br>
                surface->buffer_type = BUFFER_TYPE_EGL;<br>
<br>
                if(surface->egl_back == NULL)<br>
-                       surface->egl_back = calloc(1, sizeof *surface->egl_back);<br>
+                       surface->egl_back = zalloc(sizeof *surface->egl_back);<br>
<br>
                weston_buffer_reference(&surface->egl_back->buffer_ref, buffer);<br>
                surface->egl_back->resource_handle =<br>
@@ -1725,7 +1725,7 @@ rpi_renderer_create(struct weston_compositor *compositor,<br>
<br>
        weston_log("Initializing the DispmanX compositing renderer\n");<br>
<br>
-       renderer = calloc(1, sizeof *renderer);<br>
+       renderer = zalloc(sizeof *renderer);<br>
        if (renderer == NULL)<br>
                return -1;<br>
<br>
@@ -1797,8 +1797,8 @@ rpi_renderer_output_create(struct weston_output *base,<br>
<br>
        assert(base->renderer_state == NULL);<br>
<br>
-       output = calloc(1, sizeof *output);<br>
-       if (!output)<br>
+       output = zalloc(sizeof *output);<br>
+       if (output == NULL)<br>
                return -1;<br>
<br>
        output->display = display;<br>
diff --git a/src/text-backend.c b/src/text-backend.c<br>
index e9578a4..6246b30 100644<br>
--- a/src/text-backend.c<br>
+++ b/src/text-backend.c<br>
@@ -357,7 +357,9 @@ static void text_input_manager_create_text_input(struct wl_client *client,<br>
        struct text_input_manager *text_input_manager = wl_resource_get_user_data(resource);<br>
        struct text_input *text_input;<br>
<br>
-       text_input = calloc(1, sizeof *text_input);<br>
+       text_input = zalloc(sizeof *text_input);<br>
+       if (text_input == NULL)<br>
+               return;<br>
<br>
        text_input->resource =<br>
                wl_resource_create(client, &wl_text_input_interface, 1, id);<br>
@@ -409,7 +411,9 @@ text_input_manager_create(struct weston_compositor *ec)<br>
 {<br>
        struct text_input_manager *text_input_manager;<br>
<br>
-       text_input_manager = calloc(1, sizeof *text_input_manager);<br>
+       text_input_manager = zalloc(sizeof *text_input_manager);<br>
+       if (text_input_manager == NULL)<br>
+               return;<br>
<br>
        text_input_manager->ec = ec;<br>
<br>
@@ -726,7 +730,7 @@ input_method_context_create(struct text_input *model,<br>
        if (!input_method->input_method_binding)<br>
                return;<br>
<br>
-       context = calloc(1, sizeof *context);<br>
+       context = zalloc(sizeof *context);<br>
        if (context == NULL)<br>
                return;<br>
<br>
@@ -913,7 +917,9 @@ handle_seat_created(struct wl_listener *listener,<br>
        struct input_method *input_method;<br>
        struct weston_compositor *ec = seat->compositor;<br>
<br>
-       input_method = calloc(1, sizeof *input_method);<br>
+       input_method = zalloc(sizeof *input_method);<br>
+       if (input_method == NULL)<br>
+               return;<br>
<br>
        input_method->seat = seat;<br>
        input_method->model = NULL;<br>
@@ -972,7 +978,9 @@ text_backend_init(struct weston_compositor *ec)<br>
 {<br>
        struct text_backend *text_backend;<br>
<br>
-       text_backend = calloc(1, sizeof(*text_backend));<br>
+       text_backend = zalloc(sizeof(*text_backend));<br>
+       if (text_backend == NULL)<br>
+               return -1;<br>
<br>
        text_backend->compositor = ec;<br>
<br>
diff --git a/src/vaapi-recorder.c b/src/vaapi-recorder.c<br>
index 921494d..a469391 100644<br>
--- a/src/vaapi-recorder.c<br>
+++ b/src/vaapi-recorder.c<br>
@@ -951,8 +951,8 @@ vaapi_recorder_create(int drm_fd, int width, int height, const char *filename)<br>
        int major, minor;<br>
        int flags;<br>
<br>
-       r = calloc(1, sizeof *r);<br>
-       if (!r)<br>
+       r = zalloc(sizeof *r);<br>
+       if (r == NULL)<br>
                return NULL;<br>
<br>
        r->width = width;<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>