Fix potential leak on allocation failure in quirc_resize().

This commit is contained in:
Daniel Beer 2017-05-18 19:29:02 +12:00
parent c4abca0eec
commit 3c31aa0987

View file

@ -54,8 +54,12 @@ int quirc_resize(struct quirc *q, int w, int h)
if (sizeof(*q->image) != sizeof(*q->pixels)) { if (sizeof(*q->image) != sizeof(*q->pixels)) {
size_t new_size = w * h * sizeof(quirc_pixel_t); size_t new_size = w * h * sizeof(quirc_pixel_t);
quirc_pixel_t *new_pixels = realloc(q->pixels, new_size); quirc_pixel_t *new_pixels = realloc(q->pixels, new_size);
if (!new_pixels)
if (!new_pixels) {
free(new_image);
return -1; return -1;
}
q->pixels = new_pixels; q->pixels = new_pixels;
} }