Skip to content

Commit dbee903

Browse files
宋文武slouken
宋文武
authored andcommitted
IMG_stb: Fix a memory leak for PNG.
(cherry picked from commit 0dc1f1c)
1 parent 9ec08fd commit dbee903

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/IMG_stb.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ SDL_Surface *IMG_LoadSTB_RW(SDL_RWops *src)
157157
int colorkey_index = -1;
158158
SDL_bool has_alpha = SDL_FALSE;
159159
SDL_Palette *palette = surface->format->palette;
160+
161+
/* FIXME: This sucks. It'd be better to allocate the surface first, then
162+
* write directly to the pixel buffer:
163+
* https://github.com/nothings/stb/issues/58
164+
* -flibit
165+
*/
166+
surface->flags &= ~SDL_PREALLOC;
167+
160168
if (palette) {
161169
int i;
162170
Uint8 *palette_bytes = (Uint8 *)palette_colors;
@@ -185,15 +193,6 @@ SDL_Surface *IMG_LoadSTB_RW(SDL_RWops *src)
185193
} else if (has_colorkey) {
186194
SDL_SetColorKey(surface, SDL_TRUE, colorkey_index);
187195
}
188-
189-
/* FIXME: This sucks. It'd be better to allocate the surface first, then
190-
* write directly to the pixel buffer:
191-
* https://github.com/nothings/stb/issues/58
192-
* -flibit
193-
*/
194-
if (surface) {
195-
surface->flags &= ~SDL_PREALLOC;
196-
}
197196
}
198197

199198
} else if (format == STBI_grey || format == STBI_rgb || format == STBI_rgb_alpha) {

0 commit comments

Comments
 (0)