Check zalloc return for out of memory situation
Most zalloc calls in weston are checked, this fixes a handful that were
being ignored. As found by `grep -EIsr "[^x]zalloc\(" . -A1`
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
This commit is contained in:
committed by
Kristian Høgsberg
parent
4c3661fd7b
commit
bfd74f40f3
@@ -256,6 +256,12 @@ wayland_output_get_shm_buffer(struct wayland_output *output)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sb = zalloc(sizeof *sb);
|
sb = zalloc(sizeof *sb);
|
||||||
|
if (sb == NULL) {
|
||||||
|
weston_log("could not zalloc %ld memory for sb: %m\n", sizeof *sb);
|
||||||
|
close(fd);
|
||||||
|
free(data);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
sb->output = output;
|
sb->output = output;
|
||||||
wl_list_init(&sb->free_link);
|
wl_list_init(&sb->free_link);
|
||||||
|
|||||||
+1
-1
@@ -330,9 +330,9 @@ udev_seat_create(struct udev_input *input, const char *seat_name)
|
|||||||
struct udev_seat *seat;
|
struct udev_seat *seat;
|
||||||
|
|
||||||
seat = zalloc(sizeof *seat);
|
seat = zalloc(sizeof *seat);
|
||||||
|
|
||||||
if (!seat)
|
if (!seat)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
weston_seat_init(&seat->base, c, seat_name);
|
weston_seat_init(&seat->base, c, seat_name);
|
||||||
seat->base.led_update = udev_seat_led_update;
|
seat->base.led_update = udev_seat_led_update;
|
||||||
|
|
||||||
|
|||||||
+20
-13
@@ -449,6 +449,17 @@ weston_recorder_frame_notify(struct wl_listener *listener, void *data)
|
|||||||
weston_recorder_destroy(recorder);
|
weston_recorder_destroy(recorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
weston_recorder_free(struct weston_recorder *recorder)
|
||||||
|
{
|
||||||
|
if (recorder == NULL)
|
||||||
|
return;
|
||||||
|
free(recorder->rect);
|
||||||
|
free(recorder->tmpbuf);
|
||||||
|
free(recorder->frame);
|
||||||
|
free(recorder);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
weston_recorder_create(struct weston_output *output, const char *filename)
|
weston_recorder_create(struct weston_output *output, const char *filename)
|
||||||
{
|
{
|
||||||
@@ -461,7 +472,6 @@ weston_recorder_create(struct weston_output *output, const char *filename)
|
|||||||
do_yflip = !!(compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP);
|
do_yflip = !!(compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP);
|
||||||
|
|
||||||
recorder = malloc(sizeof *recorder);
|
recorder = malloc(sizeof *recorder);
|
||||||
|
|
||||||
if (recorder == NULL) {
|
if (recorder == NULL) {
|
||||||
weston_log("%s: out of memory\n", __func__);
|
weston_log("%s: out of memory\n", __func__);
|
||||||
return;
|
return;
|
||||||
@@ -476,6 +486,12 @@ weston_recorder_create(struct weston_output *output, const char *filename)
|
|||||||
recorder->destroying = 0;
|
recorder->destroying = 0;
|
||||||
recorder->output = output;
|
recorder->output = output;
|
||||||
|
|
||||||
|
if ((recorder->frame == NULL) || (recorder->rect == NULL)) {
|
||||||
|
weston_log("%s: out of memory\n", __func__);
|
||||||
|
weston_recorder_free(recorder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (do_yflip)
|
if (do_yflip)
|
||||||
recorder->tmpbuf = NULL;
|
recorder->tmpbuf = NULL;
|
||||||
else
|
else
|
||||||
@@ -493,10 +509,7 @@ weston_recorder_create(struct weston_output *output, const char *filename)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
weston_log("unknown recorder format\n");
|
weston_log("unknown recorder format\n");
|
||||||
free(recorder->rect);
|
weston_recorder_free(recorder);
|
||||||
free(recorder->tmpbuf);
|
|
||||||
free(recorder->frame);
|
|
||||||
free(recorder);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,10 +518,7 @@ weston_recorder_create(struct weston_output *output, const char *filename)
|
|||||||
|
|
||||||
if (recorder->fd < 0) {
|
if (recorder->fd < 0) {
|
||||||
weston_log("problem opening output file %s: %m\n", filename);
|
weston_log("problem opening output file %s: %m\n", filename);
|
||||||
free(recorder->rect);
|
weston_recorder_free(recorder);
|
||||||
free(recorder->tmpbuf);
|
|
||||||
free(recorder->frame);
|
|
||||||
free(recorder);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,11 +537,8 @@ weston_recorder_destroy(struct weston_recorder *recorder)
|
|||||||
{
|
{
|
||||||
wl_list_remove(&recorder->frame_listener.link);
|
wl_list_remove(&recorder->frame_listener.link);
|
||||||
close(recorder->fd);
|
close(recorder->fd);
|
||||||
free(recorder->tmpbuf);
|
|
||||||
free(recorder->frame);
|
|
||||||
free(recorder->rect);
|
|
||||||
recorder->output->disable_planes--;
|
recorder->output->disable_planes--;
|
||||||
free(recorder);
|
weston_recorder_free(recorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
+1
-1
@@ -373,9 +373,9 @@ udev_seat_create(struct udev_input *input, const char *seat_name)
|
|||||||
struct udev_seat *seat;
|
struct udev_seat *seat;
|
||||||
|
|
||||||
seat = zalloc(sizeof *seat);
|
seat = zalloc(sizeof *seat);
|
||||||
|
|
||||||
if (!seat)
|
if (!seat)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
weston_seat_init(&seat->base, c, seat_name);
|
weston_seat_init(&seat->base, c, seat_name);
|
||||||
seat->base.led_update = drm_led_update;
|
seat->base.led_update = drm_led_update;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user