From 445a19ec804d7d91d7cb04cb1620a06601d59a95 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Tue, 19 Sep 2023 19:08:22 +0200 Subject: [PATCH] =?UTF-8?q?chore(linux):=20Extract=20free=5Finfo=20method?= =?UTF-8?q?=20in=20kmpdetails.c=20=F0=9F=8F=98=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add guard to kmpdetails.h. --- linux/ibus-keyman/src/kmpdetails.c | 28 ++++++++++++++++++++-------- linux/ibus-keyman/src/kmpdetails.h | 7 ++++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/linux/ibus-keyman/src/kmpdetails.c b/linux/ibus-keyman/src/kmpdetails.c index eba95f4ef97..18ffde73ac8 100644 --- a/linux/ibus-keyman/src/kmpdetails.c +++ b/linux/ibus-keyman/src/kmpdetails.c @@ -455,6 +455,24 @@ kmp_json_status free_keyboard_details(keyboard_details *kbd_details) return JSON_OK; } +void free_info(gpointer data) { + kmp_info *info = (kmp_info *)data; + if (info->name) + g_free(info->name); + if (info->version) + g_free(info->version); + if (info->copyright) + g_free(info->copyright); + if (info->author_desc) + g_free(info->author_desc); + if (info->author_url) + g_free(info->author_url); + if (info->website_desc) + g_free(info->website_desc); + if (info->website_url) + g_free(info->website_url); +} + kmp_json_status free_kmp_details(kmp_details * details) { g_assert(details != NULL); @@ -462,15 +480,9 @@ kmp_json_status free_kmp_details(kmp_details * details) g_free(details->system.keymanDeveloperVersion); g_free(details->options.readmeFile); g_free(details->options.graphicFile); - g_free(details->info.name); - g_free(details->info.version); - g_free(details->info.copyright); - g_free(details->info.author_desc); - g_free(details->info.author_url); - g_free(details->info.website_desc); - g_free(details->info.website_url); + free_info(&details->info); if (details->keyboards != NULL) { - g_list_free_full(details->keyboards, (GDestroyNotify)free_keyboard); + g_list_free_full(details->keyboards, (GDestroyNotify)free_keyboard); } if (details->files != NULL) { g_list_free_full(details->files, (GDestroyNotify)free_fileinfo); diff --git a/linux/ibus-keyman/src/kmpdetails.h b/linux/ibus-keyman/src/kmpdetails.h index 3bcf6a97390..586f815baef 100644 --- a/linux/ibus-keyman/src/kmpdetails.h +++ b/linux/ibus-keyman/src/kmpdetails.h @@ -1,3 +1,6 @@ +#ifndef __KMPDETAILS_H__ +#define __KMPDETAILS_H__ + // kmp details from json #include @@ -75,4 +78,6 @@ kmp_json_status get_kmp_details(const gchar *kmp_dir, kmp_details *details); kmp_json_status free_kmp_details(kmp_details * details); kmp_json_status get_keyboard_details(const gchar *kmp_dir, const gchar *id, keyboard_details *details); kmp_json_status free_keyboard_details(keyboard_details * details); -kmp_json_status print_kmp_details(kmp_details * details); \ No newline at end of file +kmp_json_status print_kmp_details(kmp_details * details); + +#endif // __KMPDETAILS_H__