mirror of
https://github.com/libretro/RetroArch
synced 2025-04-09 21:45:45 +00:00
(Playlist management tasks) Fix potential heap-use-after-free errors
This commit is contained in:
parent
4a91b11806
commit
6f51ef5966
@ -99,34 +99,50 @@ static void free_pl_manager_handle(pl_manager_handle_t *pl_manager)
|
|||||||
pl_manager = NULL;
|
pl_manager = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pl_manager_write_playlist(
|
static void cb_task_pl_manager(
|
||||||
playlist_t *playlist, const char *playlist_path,
|
retro_task_t *task, void *task_data,
|
||||||
bool use_old_format, bool compress)
|
void *user_data, const char *err)
|
||||||
{
|
{
|
||||||
playlist_t *cached_playlist = playlist_get_cached();
|
pl_manager_handle_t *pl_manager = NULL;
|
||||||
|
playlist_t *cached_playlist = playlist_get_cached();
|
||||||
/* Sanity check */
|
|
||||||
if (!playlist || string_is_empty(playlist_path))
|
/* If no playlist is currently cached, no action
|
||||||
|
* is required */
|
||||||
|
if (!task || !cached_playlist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Write any changes to playlist file */
|
pl_manager = (pl_manager_handle_t*)task->state;
|
||||||
playlist_write_file(playlist, use_old_format, compress);
|
|
||||||
|
if (!pl_manager)
|
||||||
/* If this is the currently cached playlist, then
|
return;
|
||||||
* it must be re-cached (otherwise changes will be
|
|
||||||
* lost if the currently cached playlist is saved
|
/* If the playlist manager task has modified the
|
||||||
* to disk for any reason...) */
|
* currently cached playlist, then it must be re-cached
|
||||||
if (cached_playlist)
|
* (otherwise changes will be lost if the currently
|
||||||
|
* cached playlist is saved to disk for any reason...) */
|
||||||
|
if (string_is_equal(
|
||||||
|
pl_manager->playlist_path,
|
||||||
|
playlist_get_conf_path(cached_playlist)))
|
||||||
{
|
{
|
||||||
if (string_is_equal(playlist_path, playlist_get_conf_path(cached_playlist)))
|
playlist_free_cached();
|
||||||
{
|
playlist_init_cached(
|
||||||
playlist_free_cached();
|
pl_manager->playlist_path, COLLECTION_SIZE,
|
||||||
playlist_init_cached(
|
pl_manager->use_old_format, pl_manager->compress);
|
||||||
playlist_path, COLLECTION_SIZE, use_old_format, compress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void task_pl_manager_free(retro_task_t *task)
|
||||||
|
{
|
||||||
|
pl_manager_handle_t *pl_manager = NULL;
|
||||||
|
|
||||||
|
if (!task)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pl_manager = (pl_manager_handle_t*)task->state;
|
||||||
|
|
||||||
|
free_pl_manager_handle(pl_manager);
|
||||||
|
}
|
||||||
|
|
||||||
/**************************/
|
/**************************/
|
||||||
/* Reset Associated Cores */
|
/* Reset Associated Cores */
|
||||||
/**************************/
|
/**************************/
|
||||||
@ -227,9 +243,8 @@ static void task_pl_manager_reset_cores_handler(retro_task_t *task)
|
|||||||
task_title[0] = '\0';
|
task_title[0] = '\0';
|
||||||
|
|
||||||
/* Save playlist changes to disk */
|
/* Save playlist changes to disk */
|
||||||
pl_manager_write_playlist(
|
playlist_write_file(
|
||||||
pl_manager->playlist,
|
pl_manager->playlist,
|
||||||
pl_manager->playlist_path,
|
|
||||||
pl_manager->use_old_format,
|
pl_manager->use_old_format,
|
||||||
pl_manager->compress);
|
pl_manager->compress);
|
||||||
|
|
||||||
@ -255,8 +270,6 @@ task_finished:
|
|||||||
|
|
||||||
if (task)
|
if (task)
|
||||||
task_set_finished(task, true);
|
task_set_finished(task, true);
|
||||||
|
|
||||||
free_pl_manager_handle(pl_manager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool task_pl_manager_reset_cores_finder(retro_task_t *task, void *user_data)
|
static bool task_pl_manager_reset_cores_finder(retro_task_t *task, void *user_data)
|
||||||
@ -319,6 +332,8 @@ bool task_push_pl_manager_reset_cores(const char *playlist_path)
|
|||||||
task->title = strdup(task_title);
|
task->title = strdup(task_title);
|
||||||
task->alternative_look = true;
|
task->alternative_look = true;
|
||||||
task->progress = 0;
|
task->progress = 0;
|
||||||
|
task->callback = cb_task_pl_manager;
|
||||||
|
task->cleanup = task_pl_manager_free;
|
||||||
|
|
||||||
/* Configure handle */
|
/* Configure handle */
|
||||||
pl_manager->playlist_path = strdup(playlist_path);
|
pl_manager->playlist_path = strdup(playlist_path);
|
||||||
@ -345,11 +360,8 @@ error:
|
|||||||
task = NULL;
|
task = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pl_manager)
|
free_pl_manager_handle(pl_manager);
|
||||||
{
|
pl_manager = NULL;
|
||||||
free(pl_manager);
|
|
||||||
pl_manager = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -758,9 +770,8 @@ static void task_pl_manager_clean_playlist_handler(retro_task_t *task)
|
|||||||
task_title[0] = '\0';
|
task_title[0] = '\0';
|
||||||
|
|
||||||
/* Save playlist changes to disk */
|
/* Save playlist changes to disk */
|
||||||
pl_manager_write_playlist(
|
playlist_write_file(
|
||||||
pl_manager->playlist,
|
pl_manager->playlist,
|
||||||
pl_manager->playlist_path,
|
|
||||||
pl_manager->use_old_format,
|
pl_manager->use_old_format,
|
||||||
pl_manager->compress);
|
pl_manager->compress);
|
||||||
|
|
||||||
@ -786,8 +797,6 @@ task_finished:
|
|||||||
|
|
||||||
if (task)
|
if (task)
|
||||||
task_set_finished(task, true);
|
task_set_finished(task, true);
|
||||||
|
|
||||||
free_pl_manager_handle(pl_manager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool task_pl_manager_clean_playlist_finder(retro_task_t *task, void *user_data)
|
static bool task_pl_manager_clean_playlist_finder(retro_task_t *task, void *user_data)
|
||||||
@ -850,6 +859,8 @@ bool task_push_pl_manager_clean_playlist(const char *playlist_path)
|
|||||||
task->title = strdup(task_title);
|
task->title = strdup(task_title);
|
||||||
task->alternative_look = true;
|
task->alternative_look = true;
|
||||||
task->progress = 0;
|
task->progress = 0;
|
||||||
|
task->callback = cb_task_pl_manager;
|
||||||
|
task->cleanup = task_pl_manager_free;
|
||||||
|
|
||||||
/* Configure handle */
|
/* Configure handle */
|
||||||
pl_manager->playlist_path = strdup(playlist_path);
|
pl_manager->playlist_path = strdup(playlist_path);
|
||||||
@ -879,11 +890,8 @@ error:
|
|||||||
task = NULL;
|
task = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pl_manager)
|
free_pl_manager_handle(pl_manager);
|
||||||
{
|
pl_manager = NULL;
|
||||||
free(pl_manager);
|
|
||||||
pl_manager = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user