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>
This commit is contained in:
Jonas Ådahl 2015-08-26 12:00:06 +08:00
parent 3de1783e50
commit 2e7fb78682
5 changed files with 15 additions and 18 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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

View file

@ -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;

View file

@ -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);
}