background image: make sure to close the farbfeld file on error
This commit is contained in:
parent
1a8175a337
commit
faac64e392
|
@ -20,18 +20,15 @@ loadff(const char *filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fread(hdr, sizeof(*hdr), LEN(hdr), f) != LEN(hdr))
|
if (fread(hdr, sizeof(*hdr), LEN(hdr), f) != LEN(hdr)) {
|
||||||
if (ferror(f)) {
|
fprintf(stderr, "fread: %s\n", ferror(f) ? "" : "Unexpected end of file reading header");
|
||||||
fprintf(stderr, "fread:");
|
fclose(f);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "fread: Unexpected end of file\n");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp("farbfeld", hdr, sizeof("farbfeld") - 1)) {
|
if (memcmp("farbfeld", hdr, sizeof("farbfeld") - 1)) {
|
||||||
fprintf(stderr, "Invalid magic value");
|
fprintf(stderr, "Invalid magic value\n");
|
||||||
|
fclose(f);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,13 +37,9 @@ loadff(const char *filename)
|
||||||
size = w * h;
|
size = w * h;
|
||||||
data = malloc(size * sizeof(uint64_t));
|
data = malloc(size * sizeof(uint64_t));
|
||||||
|
|
||||||
if (fread(data, sizeof(uint64_t), size, f) != size)
|
if (fread(data, sizeof(uint64_t), size, f) != size) {
|
||||||
if (ferror(f)) {
|
fprintf(stderr, "fread: %s\n", ferror(f) ? "" : "Unexpected end of file reading data");
|
||||||
fprintf(stderr, "fread:");
|
fclose(f);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "fread: Unexpected end of file");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +84,7 @@ bginit()
|
||||||
bgimg = XCreatePixmap(xw.dpy, xw.win, bgxi->width, bgxi->height,
|
bgimg = XCreatePixmap(xw.dpy, xw.win, bgxi->width, bgxi->height,
|
||||||
DefaultDepth(xw.dpy, xw.scr));
|
DefaultDepth(xw.dpy, xw.scr));
|
||||||
#endif // ALPHA_PATCH
|
#endif // ALPHA_PATCH
|
||||||
XPutImage(xw.dpy, bgimg, dc.gc, bgxi, 0, 0, 0, 0, bgxi->width,
|
XPutImage(xw.dpy, bgimg, dc.gc, bgxi, 0, 0, 0, 0, bgxi->width, bgxi->height);
|
||||||
bgxi->height);
|
|
||||||
XDestroyImage(bgxi);
|
XDestroyImage(bgxi);
|
||||||
XSetTile(xw.dpy, xw.bggc, bgimg);
|
XSetTile(xw.dpy, xw.bggc, bgimg);
|
||||||
XSetFillStyle(xw.dpy, xw.bggc, FillTiled);
|
XSetFillStyle(xw.dpy, xw.bggc, FillTiled);
|
||||||
|
|
Loading…
Reference in New Issue