diff --git a/include/mastodont_account.h b/include/mastodont_account.h index 459e189..cb7fcaa 100644 --- a/include/mastodont_account.h +++ b/include/mastodont_account.h @@ -107,5 +107,6 @@ void _mstdnt_val_malloc_account_call(cJSON* v, void* _type); // Cleanup void mstdnt_cleanup_account(struct mstdnt_account* acct); +void mstdnt_cleanup_accounts(struct mstdnt_account* accts, size_t len); #endif /* MASTODONT_ACCOUNT */ diff --git a/include/mastodont_search.h b/include/mastodont_search.h index 6ae3b4e..826fd26 100644 --- a/include/mastodont_search.h +++ b/include/mastodont_search.h @@ -60,4 +60,6 @@ int mastodont_search(mastodont_t* data, struct mstdnt_search_args* args, struct mstdnt_search_results* results); +void mstdnt_cleanup_search_results(struct mstdnt_search_results* res); + #endif /* MASTODONT_SEARCH_H */ diff --git a/src/account.c b/src/account.c index f650fab..c6f6771 100644 --- a/src/account.c +++ b/src/account.c @@ -187,5 +187,14 @@ MSTDNT_ACCOUNT_ACTION_FUNC_URL("unsubscribe") void mstdnt_cleanup_account(struct mstdnt_account* acct) { + if (!acct) return; cleanup_emojis(acct->emojis); } + +void mstdnt_cleanup_accounts(struct mstdnt_account* accts, size_t len) +{ + if (!accts) return; + for (int i = 0; i < len; ++i) + mstdnt_cleanup_account(accts + i); +} + diff --git a/src/query.c b/src/query.c index c2cd69d..a286483 100644 --- a/src/query.c +++ b/src/query.c @@ -107,6 +107,9 @@ char* _mstdnt_query_string(mastodont_t* data, val_ptr = escape_str; } + if (val_ptr == NULL) + break; + /* Get lengths */ key_len = strlen(key_ptr); val_len = strlen(val_ptr); diff --git a/src/request.c b/src/request.c index e14c916..9f91091 100644 --- a/src/request.c +++ b/src/request.c @@ -130,6 +130,8 @@ int mastodont_request(mastodont_t* data, struct mastodont_request_args* args) /* Optional */ if (args->callback) res = args->callback(storage->root, args->args); } + else + res = 1; cleanup_res: mastodont_fetch_results_cleanup(&results); diff --git a/src/search.c b/src/search.c index de07a9f..047ac85 100644 --- a/src/search.c +++ b/src/search.c @@ -93,3 +93,11 @@ int mastodont_search(mastodont_t* data, return mastodont_request(data, &req_args); } + +void mstdnt_cleanup_search_results(struct mstdnt_search_results* res) +{ + if (!res) return; + mstdnt_cleanup_accounts(res->accts, res->accts_len); + mstdnt_cleanup_statuses(res->statuses, res->statuses_len); + mstdnt_cleanup_tags(res->tags, res->tags_len); +}