[PATCH weston 2/2] malloc + memset -> zalloc
Peter Hutterer
peter.hutterer at who-t.net
Wed Aug 7 18:57:05 PDT 2013
And for clients using the xmalloc helper, use xzalloc.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
clients/clickdot.c | 4 +---
clients/cliptest.c | 4 +---
clients/desktop-shell.c | 16 +++++-----------
clients/dnd.c | 4 +---
clients/gears.c | 3 +--
clients/image.c | 3 +--
clients/keyboard.c | 4 +---
clients/nested.c | 6 ++----
clients/resizor.c | 4 +---
clients/tablet-shell.c | 8 ++------
clients/terminal.c | 10 +++-------
clients/view.c | 3 +--
clients/window.c | 30 +++++++++++++-----------------
clients/window.h | 3 +++
src/clipboard.c | 3 +--
src/cms-colord.c | 3 +--
src/cms-static.c | 3 +--
src/compositor-drm.c | 12 ++++--------
src/compositor-headless.c | 7 ++-----
src/compositor-rdp.c | 7 ++-----
src/compositor-rpi.c | 3 +--
src/compositor-wayland.c | 11 +++--------
src/compositor-x11.c | 8 ++------
src/compositor.c | 4 +---
src/data-device.c | 3 +--
src/evdev.c | 3 +--
src/input.c | 9 +++------
src/screenshooter.c | 3 +--
src/shell.c | 3 +--
src/tablet-shell.c | 3 +--
src/tty.c | 3 +--
src/udev-seat.c | 3 +--
src/xwayland/launcher.c | 4 +---
src/xwayland/window-manager.c | 6 ++----
tests/weston-test.c | 3 +--
35 files changed, 68 insertions(+), 138 deletions(-)
diff --git a/clients/clickdot.c b/clients/clickdot.c
index c5fbc64..aebe4db 100644
--- a/clients/clickdot.c
+++ b/clients/clickdot.c
@@ -247,9 +247,7 @@ clickdot_create(struct display *display)
{
struct clickdot *clickdot;
- clickdot = xmalloc(sizeof *clickdot);
- memset(clickdot, 0, sizeof *clickdot);
-
+ clickdot = xzalloc(sizeof *clickdot);
clickdot->window = window_create(display);
clickdot->widget = frame_create(clickdot->window, clickdot);
window_set_title(clickdot->window, "Wayland ClickDot");
diff --git a/clients/cliptest.c b/clients/cliptest.c
index 7d58551..4b77808 100644
--- a/clients/cliptest.c
+++ b/clients/cliptest.c
@@ -791,9 +791,7 @@ cliptest_create(struct display *display)
{
struct cliptest *cliptest;
- cliptest = xmalloc(sizeof *cliptest);
- memset(cliptest, 0, sizeof *cliptest);
-
+ cliptest = xzalloc(sizeof *cliptest);
cliptest->surface.geometry = &cliptest->geometry;
cliptest->surface.transform.enabled = 0;
geometry_init(&cliptest->geometry);
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 9bd0ade..b17de3a 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -409,8 +409,7 @@ panel_add_clock(struct panel *panel)
return;
}
- clock = xmalloc(sizeof *clock);
- memset(clock, 0, sizeof *clock);
+ clock = xzalloc(sizeof *clock);
clock->panel = panel;
panel->clock = clock;
clock->clock_fd = timerfd;
@@ -512,8 +511,7 @@ panel_create(struct desktop *desktop)
struct panel *panel;
struct weston_config_section *s;
- panel = xmalloc(sizeof *panel);
- memset(panel, 0, sizeof *panel);
+ panel = xzalloc(sizeof *panel);
panel->base.configure = panel_configure;
panel->window = window_create_custom(desktop->display);
@@ -582,8 +580,7 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path)
char *start, *p, *eq, **ps;
int i, j, k;
- launcher = xmalloc(sizeof *launcher);
- memset(launcher, 0, sizeof *launcher);
+ launcher = xzalloc(sizeof *launcher);
launcher->icon = load_icon_or_fallback(icon);
launcher->path = strdup(path);
@@ -841,8 +838,7 @@ unlock_dialog_create(struct desktop *desktop)
struct display *display = desktop->display;
struct unlock_dialog *dialog;
- dialog = xmalloc(sizeof *dialog);
- memset(dialog, 0, sizeof *dialog);
+ dialog = xzalloc(sizeof *dialog);
dialog->window = window_create_custom(display);
dialog->widget = frame_create(dialog->window, dialog);
@@ -987,9 +983,7 @@ background_create(struct desktop *desktop)
struct weston_config_section *s;
char *type;
- background = xmalloc(sizeof *background);
- memset(background, 0, sizeof *background);
-
+ background = xzalloc(sizeof *background);
background->base.configure = background_configure;
background->window = window_create_custom(desktop->display);
background->widget = window_add_widget(background->window, background);
diff --git a/clients/dnd.c b/clients/dnd.c
index ff46fd7..cfdf92f 100644
--- a/clients/dnd.c
+++ b/clients/dnd.c
@@ -567,9 +567,7 @@ dnd_create(struct display *display)
int32_t width, height;
unsigned int i;
- dnd = xmalloc(sizeof *dnd);
- memset(dnd, 0, sizeof *dnd);
-
+ dnd = xzalloc(sizeof *dnd);
dnd->window = window_create(display);
dnd->widget = frame_create(dnd->window, dnd);
window_set_title(dnd->window, "Wayland Drag and Drop Demo");
diff --git a/clients/gears.c b/clients/gears.c
index e7249eb..30f4e68 100644
--- a/clients/gears.c
+++ b/clients/gears.c
@@ -401,8 +401,7 @@ gears_create(struct display *display)
struct timeval tv;
int i;
- gears = malloc(sizeof *gears);
- memset(gears, 0, sizeof *gears);
+ gears = zalloc(sizeof *gears);
gears->d = display;
gears->window = window_create(display);
gears->widget = frame_create(gears->window, gears);
diff --git a/clients/image.c b/clients/image.c
index 1f3c77c..4d3f3b8 100644
--- a/clients/image.c
+++ b/clients/image.c
@@ -358,10 +358,9 @@ image_create(struct display *display, const char *filename,
struct image *image;
char *b, *copy, title[512];;
- image = malloc(sizeof *image);
+ image = zalloc(sizeof *image);
if (image == NULL)
return image;
- memset(image, 0, sizeof *image);
copy = strdup(filename);
b = basename(copy);
diff --git a/clients/keyboard.c b/clients/keyboard.c
index 5fe5d9d..9c5cbc5 100644
--- a/clients/keyboard.c
+++ b/clients/keyboard.c
@@ -836,9 +836,7 @@ keyboard_create(struct output *output, struct virtual_keyboard *virtual_keyboard
layout = get_current_layout(virtual_keyboard);
- keyboard = xmalloc(sizeof *keyboard);
- memset(keyboard, 0, sizeof *keyboard);
-
+ keyboard = xzalloc(sizeof *keyboard);
keyboard->keyboard = virtual_keyboard;
keyboard->window = window_create_custom(virtual_keyboard->display);
keyboard->widget = window_add_widget(keyboard->window, keyboard);
diff --git a/clients/nested.c b/clients/nested.c
index ced0b98..aa4bf34 100644
--- a/clients/nested.c
+++ b/clients/nested.c
@@ -404,13 +404,12 @@ compositor_create_surface(struct wl_client *client,
struct nested *nested = wl_resource_get_user_data(resource);
struct nested_surface *surface;
- surface = malloc(sizeof *surface);
+ surface = zalloc(sizeof *surface);
if (surface == NULL) {
wl_resource_post_no_memory(resource);
return;
}
- memset(surface, 0, sizeof *surface);
surface->nested = nested;
display_acquire_window_surface(nested->display,
@@ -568,10 +567,9 @@ nested_create(struct display *display)
{
struct nested *nested;
- nested = malloc(sizeof *nested);
+ nested = zalloc(sizeof *nested);
if (nested == NULL)
return nested;
- memset(nested, 0, sizeof *nested);
nested->window = window_create(display);
nested->widget = frame_create(nested->window, nested);
diff --git a/clients/resizor.c b/clients/resizor.c
index 49b2817..68e4bf9 100644
--- a/clients/resizor.c
+++ b/clients/resizor.c
@@ -233,9 +233,7 @@ resizor_create(struct display *display)
{
struct resizor *resizor;
- resizor = xmalloc(sizeof *resizor);
- memset(resizor, 0, sizeof *resizor);
-
+ resizor = xzalloc(sizeof *resizor);
resizor->window = window_create(display);
resizor->widget = frame_create(resizor->window, resizor);
window_set_title(resizor->window, "Wayland Resizor");
diff --git a/clients/tablet-shell.c b/clients/tablet-shell.c
index 3b52069..436565a 100644
--- a/clients/tablet-shell.c
+++ b/clients/tablet-shell.c
@@ -230,9 +230,7 @@ homescreen_create(struct tablet *tablet)
{
struct homescreen *homescreen;
- homescreen = xmalloc(sizeof *homescreen);
- memset(homescreen, 0, sizeof *homescreen);
-
+ homescreen = zalloc (sizeof *homescreen);
homescreen->window = window_create_custom(tablet->display);
homescreen->widget =
window_add_widget(homescreen->window, homescreen);
@@ -248,9 +246,7 @@ lockscreen_create(struct tablet *tablet)
{
struct lockscreen *lockscreen;
- lockscreen = xmalloc(sizeof *lockscreen);
- memset(lockscreen, 0, sizeof *lockscreen);
-
+ lockscreen = zalloc (sizeof *lockscreen);
lockscreen->window = window_create_custom(tablet->display);
lockscreen->widget =
window_add_widget(lockscreen->window, lockscreen);
diff --git a/clients/terminal.c b/clients/terminal.c
index 1cc26d0..32d738c 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -710,12 +710,10 @@ terminal_resize_cells(struct terminal *terminal, int width, int height)
data_pitch = width * sizeof(union utf8_char);
size = data_pitch * height;
- data = malloc(size);
+ data = zalloc(size);
attr_pitch = width * sizeof(struct attr);
data_attr = malloc(attr_pitch * height);
- tab_ruler = malloc(width);
- memset(data, 0, size);
- memset(tab_ruler, 0, width);
+ tab_ruler = zalloc(width);
attr_init(data_attr, terminal->curr_attr, width * height);
if (terminal->data && terminal->data_attr) {
if (width > terminal->width)
@@ -2552,9 +2550,7 @@ terminal_create(struct display *display)
cairo_t *cr;
cairo_text_extents_t text_extents;
- terminal = xmalloc(sizeof *terminal);
-
- memset(terminal, 0, sizeof *terminal);
+ terminal = xzalloc(sizeof *terminal);
terminal->color_scheme = &DEFAULT_COLORS;
terminal_init(terminal);
terminal->margin_top = 0;
diff --git a/clients/view.c b/clients/view.c
index 110a829..f5b1843 100644
--- a/clients/view.c
+++ b/clients/view.c
@@ -230,10 +230,9 @@ view_create(struct display *display,
GFile *file = NULL;
GError *error = NULL;
- view = malloc(sizeof *view);
+ view = zalloc(sizeof *view);
if (view == NULL)
return view;
- memset(view, 0, sizeof *view);
file = g_file_new_for_commandline_arg(filename);
basename = g_file_get_basename(file);
diff --git a/clients/window.c b/clients/window.c
index 63e6a6c..cbf8bf5 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -1608,8 +1608,7 @@ widget_create(struct window *window, struct surface *surface, void *data)
{
struct widget *widget;
- widget = xmalloc(sizeof *widget);
- memset(widget, 0, sizeof *widget);
+ widget = xzalloc(sizeof *widget);
widget->window = window;
widget->surface = surface;
widget->user_data = data;
@@ -2390,9 +2389,7 @@ frame_button_create(struct frame *frame, void *data, enum frame_button_action ty
struct frame_button *frame_button;
const char *icon = data;
- frame_button = xmalloc(sizeof *frame_button);
- memset(frame_button, 0, sizeof *frame_button);
-
+ frame_button = xzalloc (sizeof *frame_button);
frame_button->icon = cairo_image_surface_create_from_png(icon);
frame_button->widget = widget_add_widget(frame->widget, frame_button);
frame_button->frame = frame;
@@ -2621,9 +2618,7 @@ frame_create(struct window *window, void *data)
{
struct frame *frame;
- frame = xmalloc(sizeof *frame);
- memset(frame, 0, sizeof *frame);
-
+ frame = xzalloc(sizeof *frame);
frame->widget = window_add_widget(window, frame);
frame->child = widget_add_widget(frame->widget, data);
@@ -4209,8 +4204,7 @@ window_create_internal(struct display *display,
struct window *window;
struct surface *surface;
- window = xmalloc(sizeof *window);
- memset(window, 0, sizeof *window);
+ window = xzalloc(sizeof *window);
wl_list_init(&window->subsurface_list);
window->display = display;
window->parent = parent;
@@ -4562,11 +4556,10 @@ display_add_output(struct display *d, uint32_t id)
{
struct output *output;
- output = malloc(sizeof *output);
+ output = zalloc(sizeof *output);
if (output == NULL)
return;
- memset(output, 0, sizeof *output);
output->display = d;
output->scale = 1;
output->output =
@@ -4692,11 +4685,10 @@ display_add_input(struct display *d, uint32_t id)
{
struct input *input;
- input = malloc(sizeof *input);
+ input = zalloc(sizeof *input);
if (input == NULL)
return;
- memset(input, 0, sizeof *input);
input->display = d;
input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
input->pointer_focus = NULL;
@@ -4998,12 +4990,10 @@ display_create(int *argc, char *argv[])
wl_log_set_handler_client(log_handler);
- d = malloc(sizeof *d);
+ d = zalloc(sizeof *d);
if (d == NULL)
return NULL;
- memset(d, 0, sizeof *d);
-
d->display = wl_display_connect(NULL);
if (d->display == NULL) {
fprintf(stderr, "failed to connect to Wayland display: %m\n");
@@ -5353,6 +5343,12 @@ xmalloc(size_t s)
return fail_on_null(malloc(s));
}
+void *
+xzalloc(size_t s)
+{
+ return fail_on_null(zalloc(s));
+}
+
char *
xstrdup(const char *s)
{
diff --git a/clients/window.h b/clients/window.h
index e045b95..3c60081 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -27,6 +27,7 @@
#include <wayland-client.h>
#include <cairo.h>
#include "../shared/config-parser.h"
+#include "../shared/zalloc.h"
#include "subsurface-client-protocol.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
@@ -57,6 +58,8 @@ void *
fail_on_null(void *p);
void *
xmalloc(size_t s);
+void *
+xzalloc(size_t s);
char *
xstrdup(const char *s);
diff --git a/src/clipboard.c b/src/clipboard.c
index 54f06e6..5a3a02d 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -283,10 +283,9 @@ clipboard_create(struct weston_seat *seat)
{
struct clipboard *clipboard;
- clipboard = malloc(sizeof *clipboard);
+ clipboard = zalloc(sizeof *clipboard);
if (clipboard == NULL)
return NULL;
- memset(clipboard, 0, sizeof *clipboard);
clipboard->seat = seat;
clipboard->selection_listener.notify = clipboard_set_selection;
diff --git a/src/cms-colord.c b/src/cms-colord.c
index 691b2e6..4ff3aac 100644
--- a/src/cms-colord.c
+++ b/src/cms-colord.c
@@ -494,10 +494,9 @@ module_init(struct weston_compositor *ec,
weston_log("colord: initialized\n");
/* create local state object */
- cms = malloc(sizeof *cms);
+ cms = zalloc(sizeof *cms);
if (cms == NULL)
return -1;
- memset(cms, 0, sizeof *cms);
cms->ec = ec;
#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init();
diff --git a/src/cms-static.c b/src/cms-static.c
index 8a36ed9..ad54fd1 100644
--- a/src/cms-static.c
+++ b/src/cms-static.c
@@ -94,10 +94,9 @@ module_init(struct weston_compositor *ec,
weston_log("cms-static: initialized\n");
/* create local state object */
- cms = malloc(sizeof *cms);
+ cms = zalloc(sizeof *cms);
if (cms == NULL)
return -1;
- memset(cms, 0, sizeof *cms);
cms->ec = ec;
cms->destroy_listener.notify = cms_notifier_destroy;
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index a47fe36..b9e3fc9 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -234,7 +234,7 @@ drm_fb_create_dumb(struct drm_compositor *ec, unsigned width, unsigned height)
struct drm_mode_destroy_dumb destroy_arg;
struct drm_mode_map_dumb map_arg;
- fb = calloc(1, sizeof *fb);
+ fb = zalloc(sizeof *fb);
if (!fb)
return NULL;
@@ -1771,11 +1771,10 @@ create_output_for_connector(struct drm_compositor *ec,
return -1;
}
- output = malloc(sizeof *output);
+ output = zalloc(sizeof *output);
if (output == NULL)
return -1;
- memset(output, 0, sizeof *output);
output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel);
output->base.make = "unknown";
output->base.model = "unknown";
@@ -2000,7 +1999,7 @@ create_sprites(struct drm_compositor *ec)
if (!plane)
continue;
- sprite = malloc(sizeof(*sprite) + ((sizeof(uint32_t)) *
+ sprite = zalloc(sizeof(*sprite) + ((sizeof(uint32_t)) *
plane->count_formats));
if (!sprite) {
weston_log("%s: out of memory\n",
@@ -2009,8 +2008,6 @@ create_sprites(struct drm_compositor *ec)
continue;
}
- memset(sprite, 0, sizeof *sprite);
-
sprite->possible_crtcs = plane->possible_crtcs;
sprite->plane_id = plane->plane_id;
sprite->current = NULL;
@@ -2451,10 +2448,9 @@ drm_compositor_create(struct wl_display *display,
weston_log("initializing drm backend\n");
- ec = malloc(sizeof *ec);
+ ec = zalloc(sizeof *ec);
if (ec == NULL)
return NULL;
- memset(ec, 0, sizeof *ec);
/* KMS support for sprites is not complete yet, so disable the
* functionality for now. */
diff --git a/src/compositor-headless.c b/src/compositor-headless.c
index dd33242..4a0cc7f 100644
--- a/src/compositor-headless.c
+++ b/src/compositor-headless.c
@@ -95,10 +95,9 @@ headless_compositor_create_output(struct headless_compositor *c,
struct headless_output *output;
struct wl_event_loop *loop;
- output = malloc(sizeof *output);
+ output = zalloc(sizeof *output);
if (output == NULL)
return -1;
- memset(output, 0, sizeof *output);
output->mode.flags =
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
@@ -161,12 +160,10 @@ headless_compositor_create(struct wl_display *display,
{
struct headless_compositor *c;
- c = calloc(1, sizeof *c);
+ c = zalloc(sizeof *c);
if (c == NULL)
return NULL;
- memset(c, 0, sizeof *c);
-
if (weston_compositor_init(&c->base, display, argc, argv, config) < 0)
goto err_free;
diff --git a/src/compositor-rdp.c b/src/compositor-rdp.c
index 33ec77d..191d673 100644
--- a/src/compositor-rdp.c
+++ b/src/compositor-rdp.c
@@ -445,10 +445,9 @@ rdp_compositor_create_output(struct rdp_compositor *c, int width, int height,
struct wl_event_loop *loop;
struct weston_mode *currentMode, *next;
- output = malloc(sizeof *output);
+ output = zalloc(sizeof *output);
if (output == NULL)
return -1;
- memset(output, 0, sizeof *output);
wl_list_init(&output->peers);
wl_list_init(&output->base.mode_list);
@@ -991,12 +990,10 @@ rdp_compositor_create(struct wl_display *display,
char *fd_str;
int fd;
- c = malloc(sizeof *c);
+ c = zalloc(sizeof *c);
if (c == NULL)
return NULL;
- memset(c, 0, sizeof *c);
-
if (weston_compositor_init(&c->base, display, argc, argv, wconfig) < 0)
goto err_free;
diff --git a/src/compositor-rpi.c b/src/compositor-rpi.c
index af62b30..a0ac6d3 100644
--- a/src/compositor-rpi.c
+++ b/src/compositor-rpi.c
@@ -598,11 +598,10 @@ evdev_input_create(struct weston_compositor *c, struct udev *udev,
{
struct rpi_seat *seat;
- seat = malloc(sizeof *seat);
+ seat = zalloc(sizeof *seat);
if (seat == NULL)
return;
- memset(seat, 0, sizeof *seat);
weston_seat_init(&seat->base, c, "default");
seat->base.led_update = rpi_led_update;
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index f3a98a8..fbaeb29 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -249,10 +249,9 @@ wayland_compositor_create_output(struct wayland_compositor *c,
{
struct wayland_output *output;
- output = malloc(sizeof *output);
+ output = zalloc(sizeof *output);
if (output == NULL)
return -1;
- memset(output, 0, sizeof *output);
output->mode.flags =
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
@@ -629,12 +628,10 @@ display_add_seat(struct wayland_compositor *c, uint32_t id)
{
struct wayland_input *input;
- input = malloc(sizeof *input);
+ input = zalloc(sizeof *input);
if (input == NULL)
return;
- memset(input, 0, sizeof *input);
-
weston_seat_init(&input->base, &c->base, "default");
input->compositor = c;
input->seat = wl_registry_bind(c->parent.registry, id,
@@ -725,12 +722,10 @@ wayland_compositor_create(struct wl_display *display,
struct wl_event_loop *loop;
int fd;
- c = malloc(sizeof *c);
+ c = zalloc(sizeof *c);
if (c == NULL)
return NULL;
- memset(c, 0, sizeof *c);
-
if (weston_compositor_init(&c->base, display, argc, argv,
config) < 0)
goto err_free;
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 4a73253..a896612 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -813,12 +813,10 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
XCB_EVENT_MASK_KEYMAP_STATE |
XCB_EVENT_MASK_FOCUS_CHANGE;
- output = malloc(sizeof *output);
+ output = zalloc(sizeof *output);
if (output == NULL)
return NULL;
- memset(output, 0, sizeof *output);
-
output->mode.flags =
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
@@ -1464,12 +1462,10 @@ x11_compositor_create(struct wl_display *display,
weston_log("initializing x11 backend\n");
- c = malloc(sizeof *c);
+ c = zalloc(sizeof *c);
if (c == NULL)
return NULL;
- memset(c, 0, sizeof *c);
-
if (weston_compositor_init(&c->base, display, argc, argv, config) < 0)
goto err_free;
diff --git a/src/compositor.c b/src/compositor.c
index 19d84af..3213a7b 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1077,9 +1077,7 @@ weston_buffer_from_resource(struct wl_resource *resource)
buffer = container_of(listener, struct weston_buffer,
destroy_listener);
} else {
- buffer = malloc(sizeof *buffer);
- memset(buffer, 0, sizeof *buffer);
-
+ buffer = zalloc(sizeof *buffer);
buffer->resource = resource;
wl_signal_init(&buffer->destroy_signal);
buffer->destroy_listener.notify = weston_buffer_destroy_handler;
diff --git a/src/data-device.c b/src/data-device.c
index a76ae16..46081d4 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -382,13 +382,12 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
return;
}
- drag = malloc(sizeof *drag);
+ drag = zalloc(sizeof *drag);
if (drag == NULL) {
wl_resource_post_no_memory(resource);
return;
}
- memset(drag, 0, sizeof *drag);
drag->grab.interface = &drag_grab_interface;
drag->client = client;
diff --git a/src/evdev.c b/src/evdev.c
index 2febb89..a82153e 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -579,10 +579,9 @@ evdev_device_create(struct weston_seat *seat, const char *path, int device_fd)
struct weston_compositor *ec;
char devname[256] = "unknown";
- device = malloc(sizeof *device);
+ device = zalloc(sizeof *device);
if (device == NULL)
return NULL;
- memset(device, 0, sizeof *device);
ec = seat->compositor;
device->output =
diff --git a/src/input.c b/src/input.c
index 7dc6b68..e533a58 100644
--- a/src/input.c
+++ b/src/input.c
@@ -307,11 +307,10 @@ weston_pointer_create(void)
{
struct weston_pointer *pointer;
- pointer = malloc(sizeof *pointer);
+ pointer = zalloc(sizeof *pointer);
if (pointer == NULL)
return NULL;
- memset(pointer, 0, sizeof *pointer);
wl_list_init(&pointer->resource_list);
pointer->focus_listener.notify = lose_pointer_focus;
pointer->default_grab.interface = &default_pointer_grab_interface;
@@ -345,11 +344,10 @@ weston_keyboard_create(void)
{
struct weston_keyboard *keyboard;
- keyboard = malloc(sizeof *keyboard);
+ keyboard = zalloc(sizeof *keyboard);
if (keyboard == NULL)
return NULL;
- memset(keyboard, 0, sizeof *keyboard);
wl_list_init(&keyboard->resource_list);
wl_array_init(&keyboard->keys);
keyboard->focus_listener.notify = lose_keyboard_focus;
@@ -376,11 +374,10 @@ weston_touch_create(void)
{
struct weston_touch *touch;
- touch = malloc(sizeof *touch);
+ touch = zalloc(sizeof *touch);
if (touch == NULL)
return NULL;
- memset(touch, 0, sizeof *touch);
wl_list_init(&touch->resource_list);
touch->focus_listener.notify = lose_touch_focus;
touch->default_grab.interface = &default_touch_grab_interface;
diff --git a/src/screenshooter.c b/src/screenshooter.c
index 2b37071..2414015 100644
--- a/src/screenshooter.c
+++ b/src/screenshooter.c
@@ -465,12 +465,11 @@ weston_recorder_create(struct weston_output *output, const char *filename)
stride = output->current->width;
size = stride * 4 * output->current->height;
- recorder->frame = malloc(size);
+ recorder->frame = zalloc(size);
recorder->rect = malloc(size);
recorder->total = 0;
recorder->count = 0;
recorder->output = output;
- memset(recorder->frame, 0, size);
if (do_yflip)
recorder->tmpbuf = NULL;
diff --git a/src/shell.c b/src/shell.c
index 30b55c3..ebe9b9f 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -4443,11 +4443,10 @@ module_init(struct weston_compositor *ec,
unsigned int i;
struct wl_event_loop *loop;
- shell = malloc(sizeof *shell);
+ shell = zalloc(sizeof *shell);
if (shell == NULL)
return -1;
- memset(shell, 0, sizeof *shell);
shell->compositor = ec;
shell->destroy_listener.notify = shell_destroy;
diff --git a/src/tablet-shell.c b/src/tablet-shell.c
index ca63b97..b055ab2 100644
--- a/src/tablet-shell.c
+++ b/src/tablet-shell.c
@@ -527,11 +527,10 @@ module_init(struct weston_compositor *compositor,
struct tablet_shell *shell;
struct wl_event_loop *loop;
- shell = malloc(sizeof *shell);
+ shell = zalloc(sizeof *shell);
if (shell == NULL)
return -1;
- memset(shell, 0, sizeof *shell);
shell->compositor = compositor;
shell->destroy_listener.notify = tablet_shell_destroy;
diff --git a/src/tty.c b/src/tty.c
index 0ddf6e0..212deb0 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -132,11 +132,10 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
char filename[16];
struct vt_stat vts;
- tty = malloc(sizeof *tty);
+ tty = zalloc(sizeof *tty);
if (tty == NULL)
return NULL;
- memset(tty, 0, sizeof *tty);
tty->compositor = compositor;
tty->vt_func = vt_func;
diff --git a/src/udev-seat.c b/src/udev-seat.c
index 771d9bc..4c051c9 100644
--- a/src/udev-seat.c
+++ b/src/udev-seat.c
@@ -338,11 +338,10 @@ udev_seat_create(struct weston_compositor *c, const char *seat_name)
{
struct udev_seat *seat;
- seat = malloc(sizeof *seat);
+ seat = zalloc(sizeof *seat);
if (!seat)
return NULL;
- memset(seat, 0, sizeof *seat);
weston_seat_init(&seat->base, c, seat_name);
seat->base.led_update = drm_led_update;
diff --git a/src/xwayland/launcher.c b/src/xwayland/launcher.c
index 3228b53..b639479 100644
--- a/src/xwayland/launcher.c
+++ b/src/xwayland/launcher.c
@@ -325,9 +325,7 @@ module_init(struct weston_compositor *compositor,
struct weston_xserver *wxs;
char lockfile[256], display_name[8];
- wxs = malloc(sizeof *wxs);
- memset(wxs, 0, sizeof *wxs);
-
+ wxs = zalloc(sizeof *wxs);
wxs->process.cleanup = weston_xserver_cleanup;
wxs->wl_display = display;
wxs->compositor = compositor;
diff --git a/src/xwayland/window-manager.c b/src/xwayland/window-manager.c
index 257c108..d565888 100644
--- a/src/xwayland/window-manager.c
+++ b/src/xwayland/window-manager.c
@@ -990,7 +990,7 @@ weston_wm_window_create(struct weston_wm *wm,
xcb_get_geometry_cookie_t geometry_cookie;
xcb_get_geometry_reply_t *geometry_reply;
- window = malloc(sizeof *window);
+ window = zalloc(sizeof *window);
if (window == NULL) {
wm_log("failed to allocate window\n");
return;
@@ -1001,7 +1001,6 @@ weston_wm_window_create(struct weston_wm *wm,
values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE;
xcb_change_window_attributes(wm->conn, id, XCB_CW_EVENT_MASK, values);
- memset(window, 0, sizeof *window);
window->wm = wm;
window->id = id;
window->properties_dirty = 1;
@@ -1701,11 +1700,10 @@ weston_wm_create(struct weston_xserver *wxs)
int sv[2];
xcb_atom_t supported[3];
- wm = malloc(sizeof *wm);
+ wm = zalloc(sizeof *wm);
if (wm == NULL)
return NULL;
- memset(wm, 0, sizeof *wm);
wm->server = wxs;
wm->window_hash = hash_table_create();
if (wm->window_hash == NULL) {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index b625f42..bc5b6e9 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -232,11 +232,10 @@ module_init(struct weston_compositor *ec,
struct weston_test *test;
struct wl_event_loop *loop;
- test = malloc(sizeof *test);
+ test = zalloc(sizeof *test);
if (test == NULL)
return -1;
- memset(test, 0, sizeof *test);
test->compositor = ec;
weston_layer_init(&test->layer, &ec->cursor_layer.link);
--
1.8.2.1
More information about the wayland-devel
mailing list