Skip to content

Commit

Permalink
Merge pull request libretro#12157 from Jamiras/task_http_cleanup
Browse files Browse the repository at this point in the history
have http tasks clean up after themselves
  • Loading branch information
inactive123 authored Mar 16, 2021
2 parents 75fe9b7 + 501fe45 commit e62aabe
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 61 deletions.
29 changes: 0 additions & 29 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -4408,13 +4408,6 @@ static void cb_net_generic_subdir(retro_task_t *task,
subdir_path, 0, 0, 0, ACTION_OK_DL_CORE_CONTENT_DIRS_SUBDIR_LIST);*/
}

if (data)
{
if (data->data)
free(data->data);
free(data);
}

if (user_data)
free(user_data);
}
Expand Down Expand Up @@ -4453,13 +4446,6 @@ static void cb_net_generic(retro_task_t *task,
refresh = true;
menu_entries_ctl(MENU_ENTRIES_CTL_UNSET_REFRESH, &refresh);

if (data)
{
if (data->data)
free(data->data);
free(data);
}

if (!err &&
!string_ends_with_size(state->path,
FILE_PATH_INDEX_DIRS_URL,
Expand Down Expand Up @@ -4770,13 +4756,6 @@ void cb_generic_download(retro_task_t *task,
discord_avatar_set_ready(true);
#endif

if (data)
{
if (data->data)
free(data->data);
free(data);
}

if (transf)
free(transf);
}
Expand Down Expand Up @@ -5903,16 +5882,8 @@ static void netplay_refresh_rooms_cb(retro_task_t *task,
if (err)
RARCH_ERR("%s: %s\n", msg_hash_to_str(MSG_DOWNLOAD_FAILED), err);

if (data)
{
if (data->data)
free(data->data);
free(data);
}

if (user_data)
free(user_data);

}

#ifndef RARCH_CONSOLE
Expand Down
19 changes: 1 addition & 18 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -6386,13 +6386,6 @@ static void handle_discord_join_cb(retro_task_t *task,
if (err)
RARCH_ERR("%s: %s\n", msg_hash_to_str(MSG_DOWNLOAD_FAILED), err);

if (data)
{
if (data->data)
free(data->data);
free(data);
}

if (user_data)
free(user_data);
}
Expand Down Expand Up @@ -7291,10 +7284,7 @@ static void netplay_announce_cb(retro_task_t *task,
char *host_string = NULL;

if (data->len == 0)
{
free(task_data);
return;
}

buf = (char*)calloc(1, data->len + 1);

Expand All @@ -7306,7 +7296,6 @@ static void netplay_announce_cb(retro_task_t *task,
{
string_list_free(lines);
free(buf);
free(task_data);
return;
}

Expand Down Expand Up @@ -7433,7 +7422,7 @@ static void netplay_announce_cb(retro_task_t *task,

string_list_free(lines);
free(buf);
free(task_data);

if (mitm_ip)
free(mitm_ip);
if (mitm_port)
Expand Down Expand Up @@ -11637,12 +11626,6 @@ static void handle_translation_cb(
if (error)
RARCH_ERR("%s: %s\n", msg_hash_to_str(MSG_DOWNLOAD_FAILED), error);

if (data)
{
if (data->data)
free(data->data);
free(data);
}
if (user_data)
free(user_data);

Expand Down
11 changes: 4 additions & 7 deletions tasks/task_core_updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,13 @@ static void cb_http_task_core_updater_get_list(
if (!list_handle)
goto finish;

task_set_data(task, NULL); /* going to pass ownership to list_handle */

list_handle->http_data = data;
list_handle->http_task_complete = true;
list_handle->http_task_success = success;


finish:

/* Log any error messages */
Expand All @@ -258,6 +261,7 @@ static void free_core_updater_list_handle(

if (list_handle->http_data)
{
/* since we took onwership, we have to destroy it ourself */
if (list_handle->http_data->data)
free(list_handle->http_data->data);

Expand Down Expand Up @@ -644,13 +648,6 @@ void cb_http_task_core_updater_download(
RARCH_ERR("[core updater] Download of '%s' failed: %s\n",
(transf ? transf->path: "unknown"), err);

if (data)
{
if (data->data)
free(data->data);
free(data);
}

if (transf)
free(transf);
}
Expand Down
12 changes: 12 additions & 0 deletions tasks/task_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ static void task_http_transfer_handler(retro_task_t *task)
free(http);
}

static void task_http_transfer_cleanup(retro_task_t *task)
{
http_transfer_data_t* data = task_get_data(task);
if (data)
{
if (data->data)
free(data->data);
free(data);
}
}

static bool task_http_finder(retro_task_t *task, void *user_data)
{
http_handle_t *http = NULL;
Expand Down Expand Up @@ -318,6 +329,7 @@ static void* task_push_http_transfer_generic(
t->mute = mute;
t->callback = cb;
t->progress_cb = http_transfer_progress_cb;
t->cleanup = task_http_transfer_cleanup;
t->user_data = user_data;
t->progress = -1;

Expand Down
7 changes: 0 additions & 7 deletions tasks/task_pl_thumbnail_download.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,6 @@ void cb_http_task_download_pl_thumbnail(
(transf ? transf->path: "unknown"), err);
}

if (data)
{
if (data->data)
free(data->data);
free(data);
}

if (transf)
free(transf);
}
Expand Down

0 comments on commit e62aabe

Please sign in to comment.