fix memory leak in SDL_Init()

we use a static guard to only call SDL_Init() once.

Another option would be to call SDL_Quit(), but it doesn't seem to be
doing anything.

Also, fix the HTML code and add 'use strict' directive.

BUG=webp:354

Change-Id: I3c6421e2c1c8cc200556cd4092a0ead9a8b054ef
This commit is contained in:
skal
2017-07-31 12:45:07 -07:00
parent 461ae5551b
commit 6878d42720
3 changed files with 23 additions and 9 deletions

View File

@ -28,6 +28,7 @@
#include <SDL/SDL.h>
#endif
static int init_ok = 0;
int WebpToSDL(const char* data, unsigned int data_size) {
int ok = 0;
VP8StatusCode status;
@ -42,7 +43,10 @@ int WebpToSDL(const char* data, unsigned int data_size) {
return 1;
}
SDL_Init(SDL_INIT_VIDEO);
if (!init_ok) {
SDL_Init(SDL_INIT_VIDEO);
init_ok = 1;
}
status = WebPGetFeatures((uint8_t*)data, (size_t)data_size, &config.input);
if (status != VP8_STATUS_OK) goto Error;
@ -97,6 +101,7 @@ int WebpToSDL(const char* data, unsigned int data_size) {
Error:
SDL_FreeSurface(surface);
SDL_FreeSurface(screen);
WebPFreeDecBuffer(output);
return ok;
}