mirror of
https://github.com/libretro/RetroArch.git
synced 2024-12-04 06:11:17 +00:00
Merge pull request #1018 from lioncash/free
Sanitize against NULL in some free-like functions.
This commit is contained in:
commit
60bd5e8323
@ -182,6 +182,9 @@ bool libretro_get_system_info(const char *path,
|
||||
|
||||
void libretro_free_system_info(struct retro_system_info *info)
|
||||
{
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
free((void*)info->library_name);
|
||||
free((void*)info->library_version);
|
||||
free((void*)info->valid_extensions);
|
||||
|
@ -43,6 +43,9 @@ fifo_buffer_t *fifo_new(size_t size)
|
||||
|
||||
void fifo_free(fifo_buffer_t *buffer)
|
||||
{
|
||||
if(!buffer)
|
||||
return;
|
||||
|
||||
free(buffer->buffer);
|
||||
free(buffer);
|
||||
}
|
||||
|
@ -84,6 +84,9 @@ void file_list_free(file_list_t *list)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!list)
|
||||
return;
|
||||
|
||||
for (i = 0; i < list->size; i++)
|
||||
{
|
||||
free(list->list[i].path);
|
||||
|
@ -717,6 +717,10 @@ static void *d3d_init(const video_info_t *info,
|
||||
static void d3d_free(void *data)
|
||||
{
|
||||
d3d_video_t *d3d = (d3d_video_t*)data;
|
||||
|
||||
if (!d3d)
|
||||
return;
|
||||
|
||||
d3d_deinitialize(d3d);
|
||||
#ifdef HAVE_OVERLAY
|
||||
d3d_free_overlays(d3d);
|
||||
@ -1342,6 +1346,9 @@ static void d3d_free_overlay(void *data, overlay_t *overlay)
|
||||
{
|
||||
d3d_video_t *d3d = (d3d_video_t*)data;
|
||||
|
||||
if (!d3d)
|
||||
return;
|
||||
|
||||
d3d_texture_free(overlay->tex);
|
||||
d3d_vertex_buffer_free(overlay->vert_buf);
|
||||
}
|
||||
@ -1351,6 +1358,9 @@ static void d3d_free_overlays(void *data)
|
||||
unsigned i;
|
||||
d3d_video_t *d3d = (d3d_video_t*)data;
|
||||
|
||||
if (!d3d)
|
||||
return;
|
||||
|
||||
for (i = 0; i < d3d->overlays.size(); i++)
|
||||
d3d_free_overlay(d3d, &d3d->overlays[i]);
|
||||
d3d->overlays.clear();
|
||||
|
@ -36,6 +36,9 @@ void renderchain_free(void *data)
|
||||
{
|
||||
renderchain_t *chain = (renderchain_t*)data;
|
||||
|
||||
if (!chain)
|
||||
return;
|
||||
|
||||
renderchain_clear(chain);
|
||||
renderchain_destroy_stock_shader(chain);
|
||||
if (chain->tracker)
|
||||
|
@ -145,6 +145,10 @@ void renderchain_set_shaders(void *data, CGprogram &fPrg, CGprogram &vPrg)
|
||||
void renderchain_destroy_stock_shader(void *data)
|
||||
{
|
||||
renderchain_t *chain = (renderchain_t*)data;
|
||||
|
||||
if (!chain)
|
||||
return;
|
||||
|
||||
#ifdef HAVE_CG
|
||||
if (chain->fStock)
|
||||
cgDestroyProgram(chain->fStock);
|
||||
@ -156,6 +160,10 @@ void renderchain_destroy_stock_shader(void *data)
|
||||
void renderchain_destroy_shader(void *data, int i)
|
||||
{
|
||||
renderchain_t *chain = (renderchain_t*)data;
|
||||
|
||||
if (!chain)
|
||||
return;
|
||||
|
||||
#ifdef HAVE_CG
|
||||
if (chain->passes[i].fPrg)
|
||||
cgDestroyProgram(chain->passes[i].fPrg);
|
||||
|
@ -23,6 +23,9 @@ static void renderchain_free(void *data)
|
||||
{
|
||||
d3d_video_t *chain = (d3d_video_t*)data;
|
||||
|
||||
if (!chain)
|
||||
return;
|
||||
|
||||
renderchain_clear(chain);
|
||||
//renderchain_destroy_stock_shader(chain);
|
||||
#ifndef DONT_HAVE_STATE_TRACKER
|
||||
|
@ -257,6 +257,10 @@ static void twoxbr_generic_output(void *data,
|
||||
static void twoxbr_generic_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
free(filt->workers);
|
||||
free(filt);
|
||||
}
|
||||
|
@ -97,6 +97,10 @@ static void twoxsai_generic_output(void *data,
|
||||
static void twoxsai_generic_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
free(filt->workers);
|
||||
free(filt);
|
||||
}
|
||||
|
@ -154,6 +154,9 @@ static void blargg_ntsc_snes_generic_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
if(filt->ntsc)
|
||||
free(filt->ntsc);
|
||||
|
||||
|
@ -95,6 +95,10 @@ static void darken_output(void *data, unsigned *out_width, unsigned *out_height,
|
||||
static void darken_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
free(filt->workers);
|
||||
free(filt);
|
||||
}
|
||||
|
@ -96,6 +96,10 @@ static void epx_generic_output(void *data,
|
||||
static void epx_generic_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
free(filt->workers);
|
||||
free(filt);
|
||||
}
|
||||
|
@ -96,6 +96,10 @@ static void lq2x_generic_output(void *data,
|
||||
static void lq2x_generic_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
free(filt->workers);
|
||||
free(filt);
|
||||
}
|
||||
|
@ -302,6 +302,10 @@ static void phosphor2x_generic_output(void *data,
|
||||
static void phosphor2x_generic_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
free(filt->workers);
|
||||
free(filt);
|
||||
}
|
||||
|
@ -159,6 +159,10 @@ static void scale2x_generic_output(void *data,
|
||||
static void scale2x_generic_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
free(filt->workers);
|
||||
free(filt);
|
||||
}
|
||||
|
@ -96,6 +96,10 @@ static void supertwoxsai_generic_output(void *data, unsigned *out_width, unsigne
|
||||
static void supertwoxsai_generic_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
free(filt->workers);
|
||||
free(filt);
|
||||
}
|
||||
|
@ -96,6 +96,10 @@ static void supereagle_generic_output(void *data, unsigned *out_width, unsigned
|
||||
static void supereagle_generic_destroy(void *data)
|
||||
{
|
||||
struct filter_data *filt = (struct filter_data*)data;
|
||||
|
||||
if (!filt)
|
||||
return;
|
||||
|
||||
free(filt->workers);
|
||||
free(filt);
|
||||
}
|
||||
|
@ -212,6 +212,9 @@ static bool rpng_gx_convert_texture32(struct texture_image *image)
|
||||
|
||||
void texture_image_free(struct texture_image *img)
|
||||
{
|
||||
if (!img)
|
||||
return;
|
||||
|
||||
free(img->pixels);
|
||||
memset(img, 0, sizeof(*img));
|
||||
}
|
||||
|
@ -145,6 +145,9 @@ static bool png_read_chunk(FILE *file, struct png_chunk *chunk)
|
||||
|
||||
static void png_free_chunk(struct png_chunk *chunk)
|
||||
{
|
||||
if (!chunk)
|
||||
return;
|
||||
|
||||
free(chunk->data);
|
||||
chunk->data = NULL;
|
||||
}
|
||||
|
3
gfx/vg.c
3
gfx/vg.c
@ -182,6 +182,9 @@ static void vg_free(void *data)
|
||||
{
|
||||
vg_t *vg = (vg_t*)data;
|
||||
|
||||
if (!vg)
|
||||
return;
|
||||
|
||||
vgDestroyImage(vg->mImage);
|
||||
|
||||
if (vg->mFontsOn)
|
||||
|
@ -780,6 +780,10 @@ static bool xv_focus(void *data)
|
||||
static void xv_free(void *data)
|
||||
{
|
||||
xv_t *xv = (xv_t*)data;
|
||||
|
||||
if (!xv)
|
||||
return;
|
||||
|
||||
x11_destroy_input_context(&xv->xim, &xv->xic);
|
||||
XShmDetach(xv->display, &xv->shminfo);
|
||||
shmdt(xv->shminfo.shmaddr);
|
||||
|
@ -176,10 +176,13 @@ static void gx_input_free_input(void *data)
|
||||
{
|
||||
gx_input_t *gx = (gx_input_t*)data;
|
||||
|
||||
if (!gx)
|
||||
return;
|
||||
|
||||
if (gx->joypad)
|
||||
gx->joypad->destroy();
|
||||
|
||||
free(data);
|
||||
free(gx);
|
||||
}
|
||||
|
||||
static const char *gx_joypad_name(unsigned pad)
|
||||
|
@ -166,6 +166,9 @@ static void input_overlay_free_overlay(struct overlay *overlay)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!overlay)
|
||||
return;
|
||||
|
||||
for (i = 0; i < overlay->size; i++)
|
||||
texture_image_free(&overlay->descs[i].image);
|
||||
|
||||
@ -177,8 +180,13 @@ static void input_overlay_free_overlay(struct overlay *overlay)
|
||||
static void input_overlay_free_overlays(input_overlay_t *ol)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!ol)
|
||||
return;
|
||||
|
||||
for (i = 0; i < ol->size; i++)
|
||||
input_overlay_free_overlay(&ol->overlays[i]);
|
||||
|
||||
free(ol->overlays);
|
||||
}
|
||||
|
||||
|
@ -127,6 +127,9 @@ static void psp_input_free_input(void *data)
|
||||
{
|
||||
psp_input_t *psp = (psp_input_t*)data;
|
||||
|
||||
if (!psp)
|
||||
return;
|
||||
|
||||
if (psp->joypad)
|
||||
psp->joypad->destroy();
|
||||
|
||||
|
@ -132,9 +132,12 @@ static void rwebinput_input_free(void *data)
|
||||
rwebinput_input_t *rwebinput = (rwebinput_input_t*)data;
|
||||
uninited = true;
|
||||
|
||||
if (!rwebinput)
|
||||
return;
|
||||
|
||||
RWebInputDestroy(rwebinput->context);
|
||||
|
||||
free(data);
|
||||
free(rwebinput);
|
||||
}
|
||||
|
||||
static void rwebinput_input_poll(void *data)
|
||||
|
@ -230,10 +230,13 @@ static void x_input_free(void *data)
|
||||
{
|
||||
x11_input_t *x11 = (x11_input_t*)data;
|
||||
|
||||
if (!x11)
|
||||
return;
|
||||
|
||||
if (x11->joypad)
|
||||
x11->joypad->destroy();
|
||||
|
||||
free(data);
|
||||
free(x11);
|
||||
}
|
||||
|
||||
static void x_input_poll_mouse(x11_input_t *x11)
|
||||
|
@ -183,10 +183,13 @@ static void xdk_input_free_input(void *data)
|
||||
{
|
||||
xdk_input_t *xdk = (xdk_input_t*)data;
|
||||
|
||||
if (!xdk)
|
||||
return;
|
||||
|
||||
if (xdk->joypad)
|
||||
xdk->joypad->destroy();
|
||||
|
||||
free(data);
|
||||
free(xdk);
|
||||
}
|
||||
|
||||
static void *xdk_input_init(void)
|
||||
|
3
rewind.c
3
rewind.c
@ -170,6 +170,9 @@ error:
|
||||
|
||||
void state_manager_free(state_manager_t *state)
|
||||
{
|
||||
if (!state)
|
||||
return;
|
||||
|
||||
free(state->data);
|
||||
free(state->thisblock);
|
||||
free(state->nextblock);
|
||||
|
12
thread.c
12
thread.c
@ -122,6 +122,9 @@ slock_t *slock_new(void)
|
||||
|
||||
void slock_free(slock_t *lock)
|
||||
{
|
||||
if (!lock)
|
||||
return;
|
||||
|
||||
CloseHandle(lock->lock);
|
||||
free(lock);
|
||||
}
|
||||
@ -201,6 +204,9 @@ int scond_broadcast(scond_t *cond)
|
||||
|
||||
void scond_free(scond_t *cond)
|
||||
{
|
||||
if (!cond)
|
||||
return;
|
||||
|
||||
CloseHandle(cond->event);
|
||||
free(cond);
|
||||
}
|
||||
@ -279,6 +285,9 @@ slock_t *slock_new(void)
|
||||
|
||||
void slock_free(slock_t *lock)
|
||||
{
|
||||
if (!lock)
|
||||
return;
|
||||
|
||||
pthread_mutex_destroy(&lock->lock);
|
||||
free(lock);
|
||||
}
|
||||
@ -315,6 +324,9 @@ scond_t *scond_new(void)
|
||||
|
||||
void scond_free(scond_t *cond)
|
||||
{
|
||||
if (!cond)
|
||||
return;
|
||||
|
||||
pthread_cond_destroy(&cond->cond);
|
||||
free(cond);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user