From 13708a4d672c674bf98aadfb155bbf81ad4f51c2 Mon Sep 17 00:00:00 2001 From: "U. Artie Eoff" Date: Wed, 15 Jan 2014 09:36:00 -0800 Subject: [PATCH] screenshooter: check for NULL malloc and fix memleaks Signed-off-by: U. Artie Eoff --- src/screenshooter.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/screenshooter.c b/src/screenshooter.c index 26e503ce..1d1c1b38 100644 --- a/src/screenshooter.c +++ b/src/screenshooter.c @@ -190,7 +190,7 @@ screenshooter_shoot(struct wl_client *client, } if (!wl_shm_buffer_get(buffer->resource)) return; - + buffer->shm_buffer = wl_shm_buffer_get(buffer->resource); buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer); buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer); @@ -428,6 +428,11 @@ weston_recorder_create(struct weston_output *output, const char *filename) recorder = malloc(sizeof *recorder); + if (recorder == NULL) { + weston_log("%s: out of memory\n", __func__); + return; + } + stride = output->current_mode->width; size = stride * 4 * output->current_mode->height; recorder->frame = zalloc(size); @@ -454,6 +459,9 @@ weston_recorder_create(struct weston_output *output, const char *filename) break; default: weston_log("unknown recorder format\n"); + free(recorder->rect); + free(recorder->tmpbuf); + free(recorder->frame); free(recorder); return; } @@ -463,6 +471,9 @@ weston_recorder_create(struct weston_output *output, const char *filename) if (recorder->fd < 0) { weston_log("problem opening output file %s: %m\n", filename); + free(recorder->rect); + free(recorder->tmpbuf); + free(recorder->frame); free(recorder); return; }