Ensure memory is not used after free().
This commit is contained in:
parent
845dcef6ab
commit
30e9cc1f10
|
@ -90,27 +90,17 @@ void rarch_task_file_load_handler(retro_task_t *task)
|
||||||
case IMAGE_TYPE_TGA:
|
case IMAGE_TYPE_TGA:
|
||||||
case IMAGE_TYPE_BMP:
|
case IMAGE_TYPE_BMP:
|
||||||
if (!rarch_task_image_load_handler(task))
|
if (!rarch_task_image_load_handler(task))
|
||||||
goto task_finished;
|
task->finished = true;
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
if (nbio->is_finished)
|
if (nbio->is_finished)
|
||||||
goto task_finished;
|
task->finished = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task->cancelled)
|
if (task->cancelled)
|
||||||
{
|
{
|
||||||
task->error = strdup("Task canceled.");
|
task->error = strdup("Task canceled.");
|
||||||
goto task_finished;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
task_finished:
|
|
||||||
task->finished = true;
|
task->finished = true;
|
||||||
|
}
|
||||||
nbio_free(nbio->handle);
|
|
||||||
nbio->handle = NULL;
|
|
||||||
nbio->is_finished = false;
|
|
||||||
free(nbio);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,14 +210,14 @@ static void rarch_task_image_load_free_internal(nbio_handle_t *nbio)
|
||||||
{
|
{
|
||||||
nbio_image_handle_t *image = (nbio_image_handle_t*)nbio->data;
|
nbio_image_handle_t *image = (nbio_image_handle_t*)nbio->data;
|
||||||
|
|
||||||
if (image)
|
if (image) {
|
||||||
free(image);
|
|
||||||
|
|
||||||
image_transfer_free(image->handle, nbio->image_type);
|
image_transfer_free(image->handle, nbio->image_type);
|
||||||
image_texture_free(&image->ti);
|
|
||||||
|
|
||||||
image->handle = NULL;
|
image->handle = NULL;
|
||||||
image->cb = NULL;
|
image->cb = NULL;
|
||||||
|
|
||||||
|
free(image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cb_nbio_generic(nbio_handle_t *nbio, size_t *len)
|
static int cb_nbio_generic(nbio_handle_t *nbio, size_t *len)
|
||||||
|
@ -331,7 +331,7 @@ bool rarch_task_push_image_load(const char *fullpath,
|
||||||
nbio_handle_t *nbio = NULL;
|
nbio_handle_t *nbio = NULL;
|
||||||
retro_task_t *t = NULL;
|
retro_task_t *t = NULL;
|
||||||
uint32_t cb_type_hash = djb2_calculate(type);
|
uint32_t cb_type_hash = djb2_calculate(type);
|
||||||
struct nbio_t *handle = nbio_open(fullpath, NBIO_READ);
|
struct nbio_t *handle = NULL;
|
||||||
nbio_image_handle_t *image = NULL;
|
nbio_image_handle_t *image = NULL;
|
||||||
|
|
||||||
switch (cb_type_hash)
|
switch (cb_type_hash)
|
||||||
|
@ -340,26 +340,30 @@ bool rarch_task_push_image_load(const char *fullpath,
|
||||||
case CB_MENU_THUMBNAIL:
|
case CB_MENU_THUMBNAIL:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto error;
|
goto error_msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!handle)
|
t = (retro_task_t*)calloc(1, sizeof(*t));
|
||||||
goto error;
|
if (!t)
|
||||||
|
goto error_msg;
|
||||||
|
|
||||||
nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio));
|
nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio));
|
||||||
|
|
||||||
if (!nbio)
|
if (!nbio)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
image = (nbio_image_handle_t*)calloc(1, sizeof(*image));
|
handle = nbio_open(fullpath, NBIO_READ);
|
||||||
|
if (!handle)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
nbio->handle = handle;
|
||||||
|
|
||||||
|
image = (nbio_image_handle_t*)calloc(1, sizeof(*image));
|
||||||
if (!image)
|
if (!image)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
image->status = IMAGE_STATUS_TRANSFER;
|
image->status = IMAGE_STATUS_TRANSFER;
|
||||||
|
|
||||||
nbio->data = (nbio_image_handle_t*)image;
|
nbio->data = (nbio_image_handle_t*)image;
|
||||||
nbio->handle = handle;
|
|
||||||
nbio->is_finished = false;
|
nbio->is_finished = false;
|
||||||
nbio->cb = &cb_nbio_image_menu_thumbnail;
|
nbio->cb = &cb_nbio_image_menu_thumbnail;
|
||||||
nbio->status = NBIO_STATUS_TRANSFER;
|
nbio->status = NBIO_STATUS_TRANSFER;
|
||||||
|
@ -373,14 +377,8 @@ bool rarch_task_push_image_load(const char *fullpath,
|
||||||
else if (strstr(fullpath, ".tga"))
|
else if (strstr(fullpath, ".tga"))
|
||||||
nbio->image_type = IMAGE_TYPE_TGA;
|
nbio->image_type = IMAGE_TYPE_TGA;
|
||||||
|
|
||||||
|
|
||||||
nbio_begin_read(handle);
|
nbio_begin_read(handle);
|
||||||
|
|
||||||
t = (retro_task_t*)calloc(1, sizeof(*t));
|
|
||||||
|
|
||||||
if (!t)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
t->state = nbio;
|
t->state = nbio;
|
||||||
t->handler = rarch_task_file_load_handler;
|
t->handler = rarch_task_file_load_handler;
|
||||||
t->cleanup = rarch_task_image_load_free;
|
t->cleanup = rarch_task_image_load_free;
|
||||||
|
@ -393,20 +391,23 @@ bool rarch_task_push_image_load(const char *fullpath,
|
||||||
|
|
||||||
error:
|
error:
|
||||||
rarch_task_image_load_free(t);
|
rarch_task_image_load_free(t);
|
||||||
nbio_free(handle);
|
free(t);
|
||||||
if (nbio)
|
|
||||||
free(nbio);
|
|
||||||
|
|
||||||
|
error_msg:
|
||||||
RARCH_ERR("[image load] Failed to open '%s': %s.\n",
|
RARCH_ERR("[image load] Failed to open '%s': %s.\n",
|
||||||
fullpath, strerror(errno));
|
fullpath, strerror(errno));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rarch_task_image_load_free(retro_task_t *task)
|
void rarch_task_image_load_free(retro_task_t *task)
|
||||||
{
|
{
|
||||||
nbio_handle_t *nbio = task ? (nbio_handle_t*)task->state : NULL;
|
nbio_handle_t *nbio = task ? (nbio_handle_t*)task->state : NULL;
|
||||||
if (!nbio)
|
|
||||||
return;
|
|
||||||
rarch_task_image_load_free_internal(nbio);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (nbio) {
|
||||||
|
rarch_task_image_load_free_internal(nbio);
|
||||||
|
nbio_free(nbio->handle);
|
||||||
|
nbio->handle = NULL;
|
||||||
|
free(nbio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue