From dbc737226cc7c41aa72e2b8345f990a7beefb982 Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 29 Jun 2022 04:08:23 +0000 Subject: [PATCH] Fix various memleaks + overruns FossilOrigin-Name: 6c24b524226c4bb45eb53effd2b4232cabe7a5588f2e8551e4d159144f015734 --- src/account.c | 4 +++- src/lists.c | 1 + src/reply.c | 4 ++-- src/status.c | 18 ++++++++++++------ src/timeline.c | 1 + 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/account.c b/src/account.c index 1847725..20f5da9 100644 --- a/src/account.c +++ b/src/account.c @@ -757,6 +757,7 @@ void content_account_blocked(struct session* ssn, mastodont_t* api, char** data) mastodont_get_blocks(api, &m_args, &args, &storage, &accts, &accts_len); accounts_page(api, ssn, &storage, "Blocked users", accts, accts_len); + mstdnt_cleanup_accounts(accts, accts_len); } void content_account_muted(struct session* ssn, mastodont_t* api, char** data) @@ -777,7 +778,8 @@ void content_account_muted(struct session* ssn, mastodont_t* api, char** data) mastodont_get_mutes(api, &m_args, &args, &storage, &accts, &accts_len); - accounts_page(api, ssn, &storage, "Muted users", accts, accts_len); + accounts_page(api, ssn, &storage, "Muted users", accts, accts_len); + mstdnt_cleanup_accounts(accts, accts_len); } void content_account_favourites(struct session* ssn, mastodont_t* api, char** data) diff --git a/src/lists.c b/src/lists.c index 2563085..62fcf55 100644 --- a/src/lists.c +++ b/src/lists.c @@ -130,4 +130,5 @@ void list_edit(struct session* ssn, mastodont_t* api, char** data) NULL); redirect(REDIRECT_303, referer); + mastodont_storage_cleanup(&storage); } diff --git a/src/reply.c b/src/reply.c index d697642..7ef2f30 100644 --- a/src/reply.c +++ b/src/reply.c @@ -75,7 +75,7 @@ char* reply_status(struct session* ssn, char* id, struct mstdnt_status* status) // Replies size_t replies_size = 0, replies_size_orig; char* replies = NULL; - char* instance_domain = malloc(sizeof(config_instance_url)-1); + char* instance_domain = malloc(sizeof(config_instance_url)+sizeof("https:///")+1); // sscanf instead of regex works here and requires less work, we just need to trim off the slash at the end if (sscanf(config_instance_url, "https://%s/", instance_domain) == 0) @@ -85,7 +85,7 @@ char* reply_status(struct session* ssn, char* id, struct mstdnt_status* status) return NULL; } - instance_domain[strlen(instance_domain)-1] = '\0'; + instance_domain[strlen(instance_domain)] = '\0'; // Remove ports, if any. Needed for development or if // the server actually supports these char* port_val = strchr(instance_domain, ':'); diff --git a/src/status.c b/src/status.c index 0ef6a4f..a48b180 100644 --- a/src/status.c +++ b/src/status.c @@ -693,6 +693,9 @@ char* construct_status(struct session* ssn, NULL); mastodont_storage_cleanup(&reblogs_storage); mastodont_storage_cleanup(&favourites_storage); + + mstdnt_cleanup_accounts(favourites, favourites_len); + mstdnt_cleanup_accounts(reblogs, reblogs_len); } // Repoint value if it's a reblog @@ -809,6 +812,7 @@ char* construct_status(struct session* ssn, free(emoji_reactions); if (notif) free(notif_info); free(delete_status); + free(pin_status); free(interactions_html); if (parse_content != status->content) free(parse_content); @@ -881,26 +885,27 @@ void status_view_reblogs(struct session* ssn, mastodont_t* api, char** data) { struct mstdnt_args m_args; set_mstdnt_args(&m_args, ssn); - struct mstdnt_account* favourites = NULL; + struct mstdnt_account* reblogs = NULL; struct mstdnt_storage storage = { 0 }; - size_t favourites_len = 0; + size_t reblogs_len = 0; char* status_id = data[0]; mastodont_status_reblogged_by(api, &m_args, status_id, &storage, - &favourites, - &favourites_len); + &reblogs, + &reblogs_len); content_status_interactions( ssn, api, "Reblogs", - favourites, - favourites_len); + reblogs, + reblogs_len); mastodont_storage_cleanup(&storage); + mstdnt_cleanup_accounts(reblogs, reblogs_len); } void status_view_favourites(struct session* ssn, mastodont_t* api, char** data) @@ -927,6 +932,7 @@ void status_view_favourites(struct session* ssn, mastodont_t* api, char** data) favourites_len); mastodont_storage_cleanup(&storage); + mstdnt_cleanup_accounts(favourites, favourites_len); } void content_status_interactions(struct session* ssn, diff --git a/src/timeline.c b/src/timeline.c index 7f5c3d1..593b669 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -112,6 +112,7 @@ void content_timeline(struct session* ssn, mstdnt_cleanup_statuses(statuses, statuses_len); free(status_format); free(post_box); + free(header); free(timeline_options); free(navigation_box); free(output);