From 6878d42720d4bc284ed2ea0e900360f83c9fad84 Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 31 Jul 2017 12:45:07 -0700 Subject: [PATCH] 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 --- extras/webp_to_sdl.c | 7 ++++++- webp_js/index.html | 11 +++++++---- webp_js/index_wasm.html | 14 ++++++++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/extras/webp_to_sdl.c b/extras/webp_to_sdl.c index 461d4c72..3dabc46b 100755 --- a/extras/webp_to_sdl.c +++ b/extras/webp_to_sdl.c @@ -28,6 +28,7 @@ #include #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; } diff --git a/webp_js/index.html b/webp_js/index.html index 3ac9325f..10873a98 100644 --- a/webp_js/index.html +++ b/webp_js/index.html @@ -12,12 +12,15 @@ - +

WebP in JavaScript demo -

diff --git a/webp_js/index_wasm.html b/webp_js/index_wasm.html index 21950632..b77c22c4 100644 --- a/webp_js/index_wasm.html +++ b/webp_js/index_wasm.html @@ -11,6 +11,11 @@ - +

WebP demo using Web-Assembly -