From 9ff1df3390f96bf1b93a3fef5a1541a18256706d Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Wed, 2 Mar 2022 15:48:59 +0000 Subject: [PATCH] Account for arrays of pointers FossilOrigin-Name: 0aecd3a06a469ef1635b4ba3bc33a2ecde1d9fd1b869a28ad9f83ec8680b6d4d --- include/mastodont_emoji.h | 2 +- include/mastodont_status.h | 1 + src/emoji.c | 12 ++++++++---- src/pleroma.c | 3 ++- src/status.c | 11 +++++++++++ 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/mastodont_emoji.h b/include/mastodont_emoji.h index 096e80b..5502120 100644 --- a/include/mastodont_emoji.h +++ b/include/mastodont_emoji.h @@ -38,7 +38,7 @@ struct mstdnt_emoji_reaction }; void cleanup_emoji_reaction(struct mstdnt_emoji_reaction* reactions); -void cleanup_emoji_reactions(struct mstdnt_emoji_reaction* reactions); +void cleanup_emoji_reactions(struct mstdnt_emoji_reaction* reactions, size_t s); void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type); #endif /* MASTODONT_EMOJI */ diff --git a/include/mastodont_status.h b/include/mastodont_status.h index 22ddb48..ff48e18 100644 --- a/include/mastodont_status.h +++ b/include/mastodont_status.h @@ -114,6 +114,7 @@ struct mstdnt_create_status_args char* visibility; }; +void cleanup_statuses(struct mstdnt_status* statuses, size_t s); void cleanup_status(struct mstdnt_status* status); int mstdnt_load_statuses_from_result(struct mstdnt_status* status[], diff --git a/src/emoji.c b/src/emoji.c index 2e5e345..0a1b049 100644 --- a/src/emoji.c +++ b/src/emoji.c @@ -60,13 +60,17 @@ void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type) } } -void cleanup_emoji_reaction(struct mstdnt_emoji_reaction* reactions) +void cleanup_emoji_reaction(struct mstdnt_emoji_reaction* reaction) { - /* NOP for compatibility purposes */ + /* NOP, this will be implemented soon*/ return; } -void cleanup_emoji_reactions(struct mstdnt_emoji_reaction* reactions) +void cleanup_emoji_reactions(struct mstdnt_emoji_reaction* reactions, size_t s) { - if (reactions) free(reactions); + size_t i; + if (!reactions) return; + for (i = 0; i < s; ++i) + cleanup_emoji_reaction(reactions + s); + free(reactions); } diff --git a/src/pleroma.c b/src/pleroma.c index b278149..ed2e4d7 100644 --- a/src/pleroma.c +++ b/src/pleroma.c @@ -50,6 +50,7 @@ void _mstdnt_val_status_pleroma_call(cJSON* v, void* _type) void cleanup_status_pleroma(struct mstdnt_status_pleroma* pleroma) { - cleanup_emoji_reactions(pleroma->emoji_reactions); + if (!pleroma) return; + cleanup_emoji_reactions(pleroma->emoji_reactions, pleroma->emoji_reactions_len); } diff --git a/src/status.c b/src/status.c index 621d93f..3296a9e 100644 --- a/src/status.c +++ b/src/status.c @@ -345,3 +345,14 @@ void cleanup_status(struct mstdnt_status* status) cleanup_attachments(status->media_attachments); cleanup_status_pleroma(&(status->pleroma)); } + +void cleanup_statuses(struct mstdnt_status* statuses, size_t s) +{ + size_t i; + if (!statuses) return; + for (i = 0; i < s; ++i) + { + cleanup_status(statuses + i); + } + free(statuses); +}