Fix memory leak in STBI PSD loader
@@ -5844,19 +5844,28 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req
if (ri->bits_per_channel == 16) { // output bpc
stbi__uint16 *q = ((stbi__uint16 *) out) + channel;
for (i = 0; i < pixelCount; i++, q += 4) {
- if (stbi__at_eof(s)) return stbi__errpuc("bad file","PSD file too short");
+ if (stbi__at_eof(s)) {
+ STBI_FREE(out);
+ return stbi__errpuc("bad file","PSD file too short");
+ }
*q = (stbi__uint16) stbi__get16be(s);
}
} else {
stbi_uc *p = out+channel;
if (bitdepth == 16) { // input bpc
for (i = 0; i < pixelCount; i++, p += 4) {
- if (stbi__at_eof(s)) return stbi__errpuc("bad file","PSD file too short");
+ if (stbi__at_eof(s)) {
+ STBI_FREE(out);
+ return stbi__errpuc("bad file","PSD file too short");
+ }
*p = (stbi_uc) (stbi__get16be(s) >> 8);
}
} else {
for (i = 0; i < pixelCount; i++, p += 4) {
- if (stbi__at_eof(s)) return stbi__errpuc("bad file","PSD file too short");
+ if (stbi__at_eof(s)) {
+ STBI_FREE(out);
+ return stbi__errpuc("bad file","PSD file too short");
+ }
*p = stbi__get8(s);
}
}
