fix(ALabel): free g_strdup'd menu action string via closure notify
The per-menu-action string duplicated with g_strdup was never freed, leaking one string per action on every menu build and reload. Use g_signal_connect_data with (GClosureNotify)g_free so the copy is freed when the closure is destroyed.
This commit is contained in:
+9
-4
@@ -123,8 +123,9 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
|
|||||||
}
|
}
|
||||||
submenus_[key] = GTK_MENU_ITEM(item);
|
submenus_[key] = GTK_MENU_ITEM(item);
|
||||||
menuActionsMap_[key] = it->asString();
|
menuActionsMap_[key] = it->asString();
|
||||||
g_signal_connect(submenus_[key], "activate", G_CALLBACK(handleGtkMenuEvent),
|
g_signal_connect_data(submenus_[key], "activate", G_CALLBACK(handleGtkMenuEvent),
|
||||||
(gpointer)g_strdup(menuActionsMap_[key].c_str()));
|
g_strdup(menuActionsMap_[key].c_str()), (GClosureNotify)g_free,
|
||||||
|
(GConnectFlags)0);
|
||||||
}
|
}
|
||||||
g_object_unref(builder);
|
g_object_unref(builder);
|
||||||
} catch (std::runtime_error& e) {
|
} catch (std::runtime_error& e) {
|
||||||
@@ -183,7 +184,9 @@ std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_
|
|||||||
if (!threshold.isObject() || !threshold["icon"].isString() || !threshold["max"].isUInt()) {
|
if (!threshold.isObject() || !threshold["icon"].isString() || !threshold["max"].isUInt()) {
|
||||||
static bool warned = false;
|
static bool warned = false;
|
||||||
if (!warned) {
|
if (!warned) {
|
||||||
spdlog::warn("format-icons: skipping invalid threshold object, expected {\"icon\": \"...\", \"max\": N}");
|
spdlog::warn(
|
||||||
|
"format-icons: skipping invalid threshold object, expected {\"icon\": \"...\", "
|
||||||
|
"\"max\": N}");
|
||||||
warned = true;
|
warned = true;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -229,7 +232,9 @@ std::string ALabel::getIcon(uint16_t percentage, const std::vector<std::string>&
|
|||||||
if (!threshold.isObject() || !threshold["icon"].isString() || !threshold["max"].isUInt()) {
|
if (!threshold.isObject() || !threshold["icon"].isString() || !threshold["max"].isUInt()) {
|
||||||
static bool warned = false;
|
static bool warned = false;
|
||||||
if (!warned) {
|
if (!warned) {
|
||||||
spdlog::warn("format-icons: skipping invalid threshold object, expected {\"icon\": \"...\", \"max\": N}");
|
spdlog::warn(
|
||||||
|
"format-icons: skipping invalid threshold object, expected {\"icon\": \"...\", "
|
||||||
|
"\"max\": N}");
|
||||||
warned = true;
|
warned = true;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user