From e7aedb6fb9a9bdbe64fd128c099b8f7d08d014b0 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 27 May 2016 05:19:27 +0200 Subject: [PATCH] Remove unneeded async_job - plug memory leak in cheevos.c --- Makefile.common | 1 - cheevos.c | 4 + griffin/griffin.c | 1 - libretro-common/include/rthreads/async_job.h | 35 ----- libretro-common/rthreads/async_job.c | 150 ------------------- 5 files changed, 4 insertions(+), 187 deletions(-) delete mode 100644 libretro-common/include/rthreads/async_job.h delete mode 100644 libretro-common/rthreads/async_job.c diff --git a/Makefile.common b/Makefile.common index f1fe579964..c4eedb90fc 100644 --- a/Makefile.common +++ b/Makefile.common @@ -513,7 +513,6 @@ ifeq ($(HAVE_THREADS), 1) OBJ += autosave.o \ libretro-common/rthreads/rthreads.o \ libretro-common/rthreads/rsemaphore.o \ - libretro-common/rthreads/async_job.o \ gfx/video_thread_wrapper.o \ audio/audio_thread_wrapper.o DEFINES += -DHAVE_THREADS diff --git a/cheevos.c b/cheevos.c index c58e30f717..3d562dbc41 100644 --- a/cheevos.c +++ b/cheevos.c @@ -1978,7 +1978,11 @@ static unsigned cheevos_find_game_id_nes( uint8_t * data = (uint8_t *) malloc(rom_size << 14); if (!file || !data) + { + if (file) + filestream_close(file); return 0; + } /* from fceu core - need it for a correctly md5 sum */ memset(data, 0xFF, rom_size << 14); diff --git a/griffin/griffin.c b/griffin/griffin.c index f2f01d51a3..2d6ab8ea1b 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -788,7 +788,6 @@ THREAD #elif defined(HAVE_THREADS) #include "../libretro-common/rthreads/rthreads.c" #include "../libretro-common/rthreads/rsemaphore.c" -#include "../libretro-common/rthreads/async_job.c" #include "../gfx/video_thread_wrapper.c" #include "../audio/audio_thread_wrapper.c" #include "../autosave.c" diff --git a/libretro-common/include/rthreads/async_job.h b/libretro-common/include/rthreads/async_job.h deleted file mode 100644 index d98742b479..0000000000 --- a/libretro-common/include/rthreads/async_job.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 2010-2015 The RetroArch team - * - * --------------------------------------------------------------------------------------- - * The following license statement only applies to this file (async_job.h). - * --------------------------------------------------------------------------------------- - * - * Permission is hereby granted, free of charge, - * to any person obtaining a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef __LIBRETRO_SDK_ASYNC_JOB_H -#define __LIBRETRO_SDK_ASYNC_JOB_H - -typedef struct async_job async_job_t; -typedef void (*async_task_t)(void *payload); - -async_job_t *async_job_new(void); - -void async_job_free(async_job_t *ajob); - -int async_job_add(async_job_t *ajob, async_task_t task, void *payload); - -#endif /* __LIBRETRO_SDK_ASYNC_JOB_H */ diff --git a/libretro-common/rthreads/async_job.c b/libretro-common/rthreads/async_job.c deleted file mode 100644 index 01ed99d3ce..0000000000 --- a/libretro-common/rthreads/async_job.c +++ /dev/null @@ -1,150 +0,0 @@ -/* Copyright (C) 2010-2016 The RetroArch team - * - * --------------------------------------------------------------------------------------- - * The following license statement only applies to this file (async_job.c). - * --------------------------------------------------------------------------------------- - * - * Permission is hereby granted, free of charge, - * to any person obtaining a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include - -#include -#include -#include - -typedef struct async_job_node async_job_node_t; - -struct async_job_node -{ - async_task_t task; - void *payload; - async_job_node_t *next; -}; - -struct async_job -{ - async_job_node_t *first; - async_job_node_t *last; - volatile int finish; - slock_t *lock; - ssem_t *sem; - sthread_t* thread; -}; - -static void async_job_processor(void *userdata) -{ - async_job_node_t *node = NULL; - async_job_t *ajob = (async_job_t*)userdata; - - for (;;) - { - ssem_wait(ajob->sem); - - if (ajob->finish) - return; - - slock_lock(ajob->lock); - - node = ajob->first; - ajob->first = node->next; - - slock_unlock(ajob->lock); - - node->task(node->payload); - free((void*)node); - } -} - -async_job_t *async_job_new(void) -{ - async_job_t *ajob = (async_job_t*)calloc(1, sizeof(*ajob)); - - if (!ajob) - return NULL; - - ajob->lock = slock_new(); - - if (!ajob->lock) - goto error; - - ajob->sem = ssem_new(0); - - if (!ajob->sem) - goto error; - - ajob->thread = sthread_create(async_job_processor, (void*)ajob); - - if (!ajob->thread) - goto error; - - return ajob; - -error: - if (ajob->lock) - slock_free(ajob->lock); - ajob->lock = NULL; - if (ajob->sem) - ssem_free(ajob->sem); - if (ajob) - free((void*)ajob); - return NULL; -} - -void async_job_free(async_job_t *ajob) -{ - if (!ajob) - return; - - ajob->finish = 1; - ssem_signal(ajob->sem); - sthread_join(ajob->thread); - slock_free(ajob->lock); - ssem_free(ajob->sem); - - free((void*)ajob); -} - -int async_job_add(async_job_t *ajob, async_task_t task, void *payload) -{ - async_job_node_t *node; - - if (!ajob) - return -1; - - node = (async_job_node_t*)calloc(1, sizeof(*node)); - - if (!node) - return -1; - - node->task = task; - node->payload = payload; - - slock_lock(ajob->lock); - - if (ajob->first) - { - ajob->last->next = node; - ajob->last = node; - } - else - ajob->first = ajob->last = node; - - slock_unlock(ajob->lock); - ssem_signal(ajob->sem); - - return 0; -}