| Summary: | Memory leak in IMG_LoadWEBP_RW (SDL2_image-2.0.0) | ||
|---|---|---|---|
| Product: | SDL_image | Reporter: | Timur <m_t> |
| Component: | misc | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | unspecified | ||
| Hardware: | x86_64 | ||
| OS: | Windows 7 | ||
| Attachments: |
fix html report
Patch |
||
Created attachment 1485 [details]
Patch
I fixed a memory leak on error in your patch. https://hg.libsdl.org/SDL_image/rev/7a360f7dd99b Thanks! If you look at an attached html report (or my patch) you will see that i put "SDL_free(raw_data)" call before "goto error" condition. So raw_data will be freed on error too. Like this
<code>
ret = lib.webp_decode_rgb_into( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h, surface->pitch );
}
if ( raw_data ) {
SDL_free( raw_data );
}
if ( !ret ) {
error = "Failed to decode WEBP";
goto error;
}
return surface;
error:
if ( surface ) {
SDL_FreeSurface( surface );
}
if ( error ) {
IMG_SetError( error );
}
SDL_RWseek(src, start, RW_SEEK_SET);
return(NULL);
}
</code>
Anyway your solution will work too.
|
Created attachment 1484 [details] fix html report SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src) { ... // buffer for data raw_data = (uint8_t*) SDL_malloc( raw_data_size ); ... // read data from src into raw_data r = SDL_RWread(src, raw_data, 1, raw_data_size ); .... // create surface and allocate memory for sdl surface surface = SDL_CreateRGBSurface(SDL_SWSURFACE, features.width, features.height, features.has_alpha?32:24, Rmask,Gmask,Bmask,Amask); ... // decode raw_data, put result into surface ret = lib.webp_decode_rgba_into( raw_data, raw_data_size, (uint8_t ... return surface; // raw_data never be freed