summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Ådahl <jadahl@gmail.com>2015-08-26 12:00:06 +0800
committerJonas Ådahl <jadahl@gmail.com>2016-01-12 12:13:12 +0800
commit2e7fb786825472d2a4b717e0b82d216aa90fb3e0 (patch)
tree946e0c464eb65330da1b65ba1321788a3597fe8b
parent3de1783e5038639128bb37f2937eeee3e36aefe6 (diff)
downloadwayland-2e7fb786825472d2a4b717e0b82d216aa90fb3e0.tar.gz
Use zalloc instead of malloc + memset
Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
-rw-r--r--src/connection.c4
-rw-r--r--src/wayland-client.c12
-rw-r--r--src/wayland-private.h7
-rw-r--r--src/wayland-server.c6
-rw-r--r--src/wayland-shm.c4
5 files changed, 15 insertions, 18 deletions
diff --git a/src/connection.c b/src/connection.c
index 6742f19..45a2e78 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -163,10 +163,10 @@ wl_connection_create(int fd)
{
struct wl_connection *connection;
- connection = malloc(sizeof *connection);
+ connection = zalloc(sizeof *connection);
if (connection == NULL)
return NULL;
- memset(connection, 0, sizeof *connection);
+
connection->fd = fd;
return connection;
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 509be08..613767e 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -331,12 +331,10 @@ proxy_create(struct wl_proxy *factory, const struct wl_interface *interface)
struct wl_proxy *proxy;
struct wl_display *display = factory->display;
- proxy = malloc(sizeof *proxy);
+ proxy = zalloc(sizeof *proxy);
if (proxy == NULL)
return NULL;
- memset(proxy, 0, sizeof *proxy);
-
proxy->object.interface = interface;
proxy->display = display;
proxy->queue = factory->queue;
@@ -387,12 +385,10 @@ wl_proxy_create_for_id(struct wl_proxy *factory,
struct wl_proxy *proxy;
struct wl_display *display = factory->display;
- proxy = malloc(sizeof *proxy);
+ proxy = zalloc(sizeof *proxy);
if (proxy == NULL)
return NULL;
- memset(proxy, 0, sizeof *proxy);
-
proxy->object.interface = interface;
proxy->object.id = id;
proxy->display = display;
@@ -817,14 +813,12 @@ wl_display_connect_to_fd(int fd)
if (debug && (strstr(debug, "client") || strstr(debug, "1")))
debug_client = 1;
- display = malloc(sizeof *display);
+ display = zalloc(sizeof *display);
if (display == NULL) {
close(fd);
return NULL;
}
- memset(display, 0, sizeof *display);
-
display->fd = fd;
wl_map_init(&display->objects, WL_MAP_CLIENT_SIDE);
wl_event_queue_init(&display->default_queue, display);
diff --git a/src/wayland-private.h b/src/wayland-private.h
index 58ac952..0e3420c 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -29,6 +29,7 @@
#define WAYLAND_PRIVATE_H
#include <stdarg.h>
+#include <stdlib.h>
#define WL_HIDE_DEPRECATED 1
@@ -216,4 +217,10 @@ struct wl_display;
struct wl_array *
wl_display_get_additional_shm_formats(struct wl_display *display);
+static inline void *
+zalloc(size_t s)
+{
+ return calloc(1, s);
+}
+
#endif
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 55c0cf9..9e26b18 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -415,11 +415,10 @@ wl_client_create(struct wl_display *display, int fd)
struct wl_client *client;
socklen_t len;
- client = malloc(sizeof *client);
+ client = zalloc(sizeof *client);
if (client == NULL)
return NULL;
- memset(client, 0, sizeof *client);
client->display = display;
client->source = wl_event_loop_add_fd(display->loop, fd,
WL_EVENT_READABLE,
@@ -854,11 +853,10 @@ wl_socket_alloc(void)
{
struct wl_socket *s;
- s = malloc(sizeof *s);
+ s = zalloc(sizeof *s);
if (!s)
return NULL;
- memset(s, 0, sizeof *s);
s->fd = -1;
s->fd_lock = -1;
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 0cd8c11..359c3bd 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -536,12 +536,10 @@ wl_shm_buffer_begin_access(struct wl_shm_buffer *buffer)
sigbus_data = pthread_getspecific(wl_shm_sigbus_data_key);
if (sigbus_data == NULL) {
- sigbus_data = malloc(sizeof *sigbus_data);
+ sigbus_data = zalloc(sizeof *sigbus_data);
if (sigbus_data == NULL)
return;
- memset(sigbus_data, 0, sizeof *sigbus_data);
-
pthread_setspecific(wl_shm_sigbus_data_key, sigbus_data);
}