From 0140606226e4ed24bbd61f28a46735ae27176ad6 Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Fri, 25 Mar 2022 16:57:25 +0100 Subject: [PATCH] Fixed segfault on upower service restart --- src/modules/upower/upower.cpp | 2 +- src/modules/upower/upower_tooltip.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/modules/upower/upower.cpp b/src/modules/upower/upower.cpp index 00b69aa..3032679 100644 --- a/src/modules/upower/upower.cpp +++ b/src/modules/upower/upower.cpp @@ -347,7 +347,7 @@ auto UPower::update() -> void { label_.set_markup(onlySpaces ? "" : label_format); // Set icon - if (!Gtk::IconTheme::get_default()->has_icon(icon_name)) { + if (icon_name == NULL || !Gtk::IconTheme::get_default()->has_icon(icon_name)) { icon_name = (char*)"battery-missing-symbolic"; } icon_.set_from_icon_name(icon_name, Gtk::ICON_SIZE_INVALID); diff --git a/src/modules/upower/upower_tooltip.cpp b/src/modules/upower/upower_tooltip.cpp index 644b8e0..8aaba92 100644 --- a/src/modules/upower/upower_tooltip.cpp +++ b/src/modules/upower/upower_tooltip.cpp @@ -62,7 +62,9 @@ uint UPowerTooltip::updateTooltip(Devices& devices) { NULL); // Skip Line_Power and BAT0 devices - if (kind == UP_DEVICE_KIND_LINE_POWER || strcmp(native_path, "BAT0") == 0) continue; + if (kind == UP_DEVICE_KIND_LINE_POWER || native_path == NULL || strlen(native_path) == 0 || + strcmp(native_path, "BAT0") == 0) + continue; Gtk::Box* modelBox = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL); box->add(*modelBox); @@ -77,6 +79,7 @@ uint UPowerTooltip::updateTooltip(Devices& devices) { modelBox->add(*deviceIcon); // Set model + if (model == NULL) model = (gchar*)""; Gtk::Label* modelLabel = new Gtk::Label(model); modelBox->add(*modelLabel); @@ -86,7 +89,7 @@ uint UPowerTooltip::updateTooltip(Devices& devices) { // Set icon Gtk::Image* icon = new Gtk::Image(); icon->set_pixel_size(iconSize); - if (!Gtk::IconTheme::get_default()->has_icon(icon_name)) { + if (icon_name == NULL || !Gtk::IconTheme::get_default()->has_icon(icon_name)) { icon_name = (char*)"battery-missing-symbolic"; } icon->set_from_icon_name(icon_name, Gtk::ICON_SIZE_INVALID);