From b0e51ba91d343500aa2247f05bd6e47237d22af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 5 Jul 2024 23:27:13 +0800 Subject: [PATCH] Global: fix memleaks --- src/detection/wmtheme/wmtheme_linux.c | 7 ++++--- src/modules/icons/icons.c | 6 ++++++ src/modules/theme/theme.c | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/detection/wmtheme/wmtheme_linux.c b/src/detection/wmtheme/wmtheme_linux.c index 6b737a133..bed430c43 100644 --- a/src/detection/wmtheme/wmtheme_linux.c +++ b/src/detection/wmtheme/wmtheme_linux.c @@ -6,6 +6,7 @@ #include "detection/gtk_qt/gtk_qt.h" #include "detection/displayserver/displayserver.h" #include "util/stringUtils.h" +#include "util/mallocHelper.h" static bool detectWMThemeFromConfigFile(const char* configFile, const char* themeRegex, const char* defaultValue, FFstrbuf* themeOrError) { @@ -91,8 +92,8 @@ static bool detectMutter(FFstrbuf* themeOrError) static bool detectMuffin(FFstrbuf* themeOrError) { - const char* name = ffSettingsGet("/org/cinnamon/theme/name", "org.cinnamon.theme", NULL, "name", FF_VARIANT_TYPE_STRING).strValue; - const char* theme = ffSettingsGet("/org/cinnamon/desktop/wm/preferences/theme", "org.cinnamon.desktop.wm.preferences", NULL, "theme", FF_VARIANT_TYPE_STRING).strValue; + FF_AUTO_FREE const char* name = ffSettingsGet("/org/cinnamon/theme/name", "org.cinnamon.theme", NULL, "name", FF_VARIANT_TYPE_STRING).strValue; + FF_AUTO_FREE const char* theme = ffSettingsGet("/org/cinnamon/desktop/wm/preferences/theme", "org.cinnamon.desktop.wm.preferences", NULL, "theme", FF_VARIANT_TYPE_STRING).strValue; if(name == NULL && theme == NULL) { @@ -133,7 +134,7 @@ static bool detectXFWM4(FFstrbuf* themeOrError) static bool detectOpenbox(const FFstrbuf* dePrettyName, FFstrbuf* themeOrError) { FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(64); - const char *configFileSubpath = "openbox/rc.xml"; + const char *configFileSubpath = "openbox/rc.xml"; if (ffStrbufIgnCaseCompS(dePrettyName, "LXQt") == 0) configFileSubpath = "openbox/lxqt-rc.xml"; else if (ffStrbufIgnCaseCompS(dePrettyName, "LXDE") == 0) diff --git a/src/modules/icons/icons.c b/src/modules/icons/icons.c index 379a5d6a9..51671bdeb 100644 --- a/src/modules/icons/icons.c +++ b/src/modules/icons/icons.c @@ -40,6 +40,9 @@ void ffPrintIcons(FFIconsOptions* options) {FF_FORMAT_ARG_TYPE_STRBUF, &result.icons2, "icons2"}, })); } + + ffStrbufDestroy(&result.icons1); + ffStrbufDestroy(&result.icons2); } bool ffParseIconsCommandOptions(FFIconsOptions* options, const char* key, const char* value) @@ -94,6 +97,9 @@ void ffGenerateIconsJsonResult(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_m yyjson_mut_val* icons = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, icons, "icons1", &result.icons1); yyjson_mut_obj_add_strbuf(doc, icons, "icons2", &result.icons2); + + ffStrbufDestroy(&result.icons1); + ffStrbufDestroy(&result.icons2); } void ffPrintIconsHelpFormat(void) diff --git a/src/modules/theme/theme.c b/src/modules/theme/theme.c index b6eda5f06..2f0f8032c 100644 --- a/src/modules/theme/theme.c +++ b/src/modules/theme/theme.c @@ -40,6 +40,9 @@ void ffPrintTheme(FFThemeOptions* options) {FF_FORMAT_ARG_TYPE_STRBUF, &result.theme2, "theme2"}, })); } + + ffStrbufDestroy(&result.theme1); + ffStrbufDestroy(&result.theme2); } bool ffParseThemeCommandOptions(FFThemeOptions* options, const char* key, const char* value) @@ -94,6 +97,9 @@ void ffGenerateThemeJsonResult(FF_MAYBE_UNUSED FFThemeOptions* options, yyjson_m yyjson_mut_val* theme = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, theme, "theme1", &result.theme1); yyjson_mut_obj_add_strbuf(doc, theme, "theme2", &result.theme2); + + ffStrbufDestroy(&result.theme1); + ffStrbufDestroy(&result.theme2); } void ffPrintThemeHelpFormat(void)