aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Fan <ianfan0@gmail.com>2018-11-01 23:55:41 +0000
committeremersion <contact@emersion.fr>2018-11-24 23:10:05 +0100
commit6e2dccc2e96a9e7d5ff7da6ad097c0360ece2693 (patch)
tree2a07fbcff33ea8ddfae8b88e1873a0288d2bf258
parent827e5513e030eff40323832466e8a39f11aae4eb (diff)
swayidle: when acquiring sleep lock, initialize and free variables properly
-rw-r--r--swayidle/main.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/swayidle/main.c b/swayidle/main.c
index 2b185949..4e850c92 100644
--- a/swayidle/main.c
+++ b/swayidle/main.c
@@ -81,16 +81,16 @@ static int release_lock(void *data) {
}
static void acquire_sleep_lock(void) {
- sd_bus_message *msg;
- sd_bus_error error;
+ sd_bus_message *msg = NULL;
+ sd_bus_error error = SD_BUS_ERROR_NULL;
int ret = sd_bus_call_method(bus, "org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager", "Inhibit",
&error, &msg, "ssss", "sleep", "swayidle",
"Setup Up Lock Screen", "delay");
if (ret < 0) {
- wlr_log(WLR_ERROR, "Failed to send Inhibit signal: %s",
- strerror(-ret));
+ wlr_log(WLR_ERROR, "Failed to send Inhibit signal: %s", error.message);
+ sd_bus_error_free(&error);
return;
}
@@ -98,10 +98,11 @@ static void acquire_sleep_lock(void) {
if (ret < 0) {
wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s",
strerror(-ret));
- return;
+ } else {
+ wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd);
}
-
- wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd);
+ sd_bus_error_free(&error);
+ sd_bus_message_unref(msg);
}
static int prepare_for_sleep(sd_bus_message *msg, void *userdata,