img: Fix fd leaks

Spotted by maddin200@aol.com

https://bugs.freedesktop.org/show_bug.cgi?id=90197
This commit is contained in:
Bastien Nocera 2018-05-25 13:30:35 +02:00
parent 391f77ce5e
commit 55b83062d0

View file

@ -166,12 +166,14 @@ API_EXPORTED int fp_img_save_to_file(struct fp_img *img, char *path)
r = fprintf(fd, "P5 %d %d 255\n", img->width, img->height); r = fprintf(fd, "P5 %d %d 255\n", img->width, img->height);
if (r < 0) { if (r < 0) {
fclose(fd);
fp_err("pgm header write failed, error %d", r); fp_err("pgm header write failed, error %d", r);
return r; return r;
} }
r = fwrite(img->data, 1, write_size, fd); r = fwrite(img->data, 1, write_size, fd);
if (r < write_size) { if (r < write_size) {
fclose(fd);
fp_err("short write (%d)", r); fp_err("short write (%d)", r);
return -EIO; return -EIO;
} }