Use zalloc for structs
When allocating memory for structs, use zalloc instead of malloc. This ensures the memory is zero-initialized, and reduces the risk of forgetting to initialize all struct fields. Signed-off-by: Simon Ser <contact@emersion.fr>
This commit is contained in:
parent
4b05ecb8f7
commit
5eb5620cbd
|
@ -568,10 +568,10 @@ wl_closure_init(const struct wl_message *message, uint32_t size,
|
||||||
|
|
||||||
if (size) {
|
if (size) {
|
||||||
*num_arrays = wl_message_count_arrays(message);
|
*num_arrays = wl_message_count_arrays(message);
|
||||||
closure = malloc(sizeof *closure + size +
|
closure = zalloc(sizeof *closure + size +
|
||||||
*num_arrays * sizeof(struct wl_array));
|
*num_arrays * sizeof(struct wl_array));
|
||||||
} else {
|
} else {
|
||||||
closure = malloc(sizeof *closure);
|
closure = zalloc(sizeof *closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!closure) {
|
if (!closure) {
|
||||||
|
|
|
@ -179,7 +179,7 @@ wl_event_loop_add_fd(struct wl_event_loop *loop,
|
||||||
{
|
{
|
||||||
struct wl_event_source_fd *source;
|
struct wl_event_source_fd *source;
|
||||||
|
|
||||||
source = malloc(sizeof *source);
|
source = zalloc(sizeof *source);
|
||||||
if (source == NULL)
|
if (source == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -568,7 +568,7 @@ wl_event_loop_add_timer(struct wl_event_loop *loop,
|
||||||
if (wl_timer_heap_ensure_timerfd(&loop->timers) < 0)
|
if (wl_timer_heap_ensure_timerfd(&loop->timers) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
source = malloc(sizeof *source);
|
source = zalloc(sizeof *source);
|
||||||
if (source == NULL)
|
if (source == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -718,7 +718,7 @@ wl_event_loop_add_signal(struct wl_event_loop *loop,
|
||||||
struct wl_event_source_signal *source;
|
struct wl_event_source_signal *source;
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
|
|
||||||
source = malloc(sizeof *source);
|
source = zalloc(sizeof *source);
|
||||||
if (source == NULL)
|
if (source == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -775,7 +775,7 @@ wl_event_loop_add_idle(struct wl_event_loop *loop,
|
||||||
{
|
{
|
||||||
struct wl_event_source_idle *source;
|
struct wl_event_source_idle *source;
|
||||||
|
|
||||||
source = malloc(sizeof *source);
|
source = zalloc(sizeof *source);
|
||||||
if (source == NULL)
|
if (source == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -885,7 +885,7 @@ wl_event_loop_create(void)
|
||||||
{
|
{
|
||||||
struct wl_event_loop *loop;
|
struct wl_event_loop *loop;
|
||||||
|
|
||||||
loop = malloc(sizeof *loop);
|
loop = zalloc(sizeof *loop);
|
||||||
if (loop == NULL)
|
if (loop == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
@ -343,7 +343,7 @@ wl_display_create_queue(struct wl_display *display)
|
||||||
{
|
{
|
||||||
struct wl_event_queue *queue;
|
struct wl_event_queue *queue;
|
||||||
|
|
||||||
queue = malloc(sizeof *queue);
|
queue = zalloc(sizeof *queue);
|
||||||
if (queue == NULL)
|
if (queue == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
@ -1062,7 +1062,7 @@ wl_display_create(void)
|
||||||
if (debug && (strstr(debug, "server") || strstr(debug, "1")))
|
if (debug && (strstr(debug, "server") || strstr(debug, "1")))
|
||||||
debug_server = 1;
|
debug_server = 1;
|
||||||
|
|
||||||
display = malloc(sizeof *display);
|
display = zalloc(sizeof *display);
|
||||||
if (display == NULL)
|
if (display == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1238,7 +1238,7 @@ wl_global_create(struct wl_display *display,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
global = malloc(sizeof *global);
|
global = zalloc(sizeof *global);
|
||||||
if (global == NULL)
|
if (global == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1822,7 +1822,7 @@ wl_resource_create(struct wl_client *client,
|
||||||
{
|
{
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
|
|
||||||
resource = malloc(sizeof *resource);
|
resource = zalloc(sizeof *resource);
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1888,7 +1888,7 @@ wl_display_add_protocol_logger(struct wl_display *display,
|
||||||
{
|
{
|
||||||
struct wl_protocol_logger *logger;
|
struct wl_protocol_logger *logger;
|
||||||
|
|
||||||
logger = malloc(sizeof *logger);
|
logger = zalloc(sizeof *logger);
|
||||||
if (!logger)
|
if (!logger)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
@ -223,7 +223,7 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = malloc(sizeof *buffer);
|
buffer = zalloc(sizeof *buffer);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
wl_client_post_no_memory(client);
|
wl_client_post_no_memory(client);
|
||||||
return;
|
return;
|
||||||
|
@ -312,7 +312,7 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
|
||||||
goto err_close;
|
goto err_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
pool = malloc(sizeof *pool);
|
pool = zalloc(sizeof *pool);
|
||||||
if (pool == NULL) {
|
if (pool == NULL) {
|
||||||
wl_client_post_no_memory(client);
|
wl_client_post_no_memory(client);
|
||||||
goto err_close;
|
goto err_close;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user