Skip to content

Commit 0140606

Browse files
committed
Fixed segfault on upower service restart
1 parent d1d73b5 commit 0140606

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: src/modules/upower/upower.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ auto UPower::update() -> void {
347347
label_.set_markup(onlySpaces ? "" : label_format);
348348

349349
// Set icon
350-
if (!Gtk::IconTheme::get_default()->has_icon(icon_name)) {
350+
if (icon_name == NULL || !Gtk::IconTheme::get_default()->has_icon(icon_name)) {
351351
icon_name = (char*)"battery-missing-symbolic";
352352
}
353353
icon_.set_from_icon_name(icon_name, Gtk::ICON_SIZE_INVALID);

Diff for: src/modules/upower/upower_tooltip.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ uint UPowerTooltip::updateTooltip(Devices& devices) {
6262
NULL);
6363

6464
// Skip Line_Power and BAT0 devices
65-
if (kind == UP_DEVICE_KIND_LINE_POWER || strcmp(native_path, "BAT0") == 0) continue;
65+
if (kind == UP_DEVICE_KIND_LINE_POWER || native_path == NULL || strlen(native_path) == 0 ||
66+
strcmp(native_path, "BAT0") == 0)
67+
continue;
6668

6769
Gtk::Box* modelBox = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL);
6870
box->add(*modelBox);
@@ -77,6 +79,7 @@ uint UPowerTooltip::updateTooltip(Devices& devices) {
7779
modelBox->add(*deviceIcon);
7880

7981
// Set model
82+
if (model == NULL) model = (gchar*)"";
8083
Gtk::Label* modelLabel = new Gtk::Label(model);
8184
modelBox->add(*modelLabel);
8285

@@ -86,7 +89,7 @@ uint UPowerTooltip::updateTooltip(Devices& devices) {
8689
// Set icon
8790
Gtk::Image* icon = new Gtk::Image();
8891
icon->set_pixel_size(iconSize);
89-
if (!Gtk::IconTheme::get_default()->has_icon(icon_name)) {
92+
if (icon_name == NULL || !Gtk::IconTheme::get_default()->has_icon(icon_name)) {
9093
icon_name = (char*)"battery-missing-symbolic";
9194
}
9295
icon->set_from_icon_name(icon_name, Gtk::ICON_SIZE_INVALID);

0 commit comments

Comments
 (0)