summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Calvin Lee <cyrus296@gmail.com>2017-11-08 12:59:43 -0700
committerLibravatar Calvin Lee <cyrus296@gmail.com>2017-12-29 12:11:51 -0700
commitb9f36716b52d4566609ac64be88b8a1f65602214 (patch)
tree7ffb59b5c7e9a76c8e739ec56d4692f9e792fd49
parentCorrect context menu placement if bar is bottom (diff)
downloadsway-b9f36716b52d4566609ac64be88b8a1f65602214.tar.gz
sway-b9f36716b52d4566609ac64be88b8a1f65602214.tar.zst
sway-b9f36716b52d4566609ac64be88b8a1f65602214.zip
Plug memory `dbus_message_iter_get_signature` leak
-rw-r--r--include/swaybar/tray/dbus.h6
-rw-r--r--swaybar/tray/dbus.c8
-rw-r--r--swaybar/tray/sni.c18
-rw-r--r--swaybar/tray/tray.c2
4 files changed, 20 insertions, 14 deletions
diff --git a/include/swaybar/tray/dbus.h b/include/swaybar/tray/dbus.h
index eb9cfea7..51754464 100644
--- a/include/swaybar/tray/dbus.h
+++ b/include/swaybar/tray/dbus.h
@@ -6,6 +6,12 @@
6extern DBusConnection *conn; 6extern DBusConnection *conn;
7 7
8/** 8/**
9 * Checks the signature of the given iter against `sig`. Prefer to
10 * `dbus_message_iter_get_signature` as this one frees the intermediate string.
11 */
12bool dbus_message_iter_check_signature(DBusMessageIter *iter, const char *sig);
13
14/**
9 * Should be called in main loop to dispatch events 15 * Should be called in main loop to dispatch events
10 */ 16 */
11void dispatch_dbus(); 17void dispatch_dbus();
diff --git a/swaybar/tray/dbus.c b/swaybar/tray/dbus.c
index 8e719fd9..46a1c807 100644
--- a/swaybar/tray/dbus.c
+++ b/swaybar/tray/dbus.c
@@ -1,5 +1,6 @@
1#define _XOPEN_SOURCE 700 1#define _XOPEN_SOURCE 700
2#include <stdio.h> 2#include <stdio.h>
3#include <string.h>
3#include <stdlib.h> 4#include <stdlib.h>
4#include <stdint.h> 5#include <stdint.h>
5#include <stdbool.h> 6#include <stdbool.h>
@@ -137,6 +138,13 @@ static void dispatch_status(DBusConnection *connection, DBusDispatchStatus new_s
137 138
138/* Public functions below */ 139/* Public functions below */
139 140
141bool dbus_message_iter_check_signature(DBusMessageIter *iter, const char *sig) {
142 char *msg_sig = dbus_message_iter_get_signature(iter);
143 int result = strcmp(msg_sig, sig);
144 dbus_free(msg_sig);
145 return (result == 0);
146}
147
140void dispatch_dbus() { 148void dispatch_dbus() {
141 if (!should_dispatch || !conn) { 149 if (!should_dispatch || !conn) {
142 return; 150 return;
diff --git a/swaybar/tray/sni.c b/swaybar/tray/sni.c
index 7e09f414..401a0091 100644
--- a/swaybar/tray/sni.c
+++ b/swaybar/tray/sni.c
@@ -71,17 +71,13 @@ static void reply_icon(DBusPendingCall *pending, void *_data) {
71 71
72 // Each if here checks the types above before recursing 72 // Each if here checks the types above before recursing
73 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { 73 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
74 sway_log(L_ERROR, "Relpy type incorrect"); 74 sway_log(L_ERROR, "Icon relpy type incorrect");
75 sway_log(L_ERROR, "Should be \"v\", is \"%s\"",
76 dbus_message_iter_get_signature(&iter));
77 goto bail; 75 goto bail;
78 } 76 }
79 dbus_message_iter_recurse(&iter, &variant); 77 dbus_message_iter_recurse(&iter, &variant);
80 78
81 if (strcmp("a(iiay)", dbus_message_iter_get_signature(&variant)) != 0) { 79 if (dbus_message_iter_check_signature(&variant, "a(iiay)")) {
82 sway_log(L_ERROR, "Relpy type incorrect"); 80 sway_log(L_ERROR, "Icon relpy type incorrect");
83 sway_log(L_ERROR, "Should be \"a(iiay)\", is \"%s\"",
84 dbus_message_iter_get_signature(&variant));
85 goto bail; 81 goto bail;
86 } 82 }
87 83
@@ -237,18 +233,14 @@ static void reply_icon_name(DBusPendingCall *pending, void *_data) {
237 233
238 dbus_message_iter_init(reply, &iter); 234 dbus_message_iter_init(reply, &iter);
239 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { 235 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
240 sway_log(L_ERROR, "Relpy type incorrect"); 236 sway_log(L_ERROR, "Icon name relpy type incorrect");
241 sway_log(L_ERROR, "Should be \"v\", is \"%s\"",
242 dbus_message_iter_get_signature(&iter));
243 goto bail; 237 goto bail;
244 } 238 }
245 dbus_message_iter_recurse(&iter, &variant); 239 dbus_message_iter_recurse(&iter, &variant);
246 240
247 241
248 if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_STRING) { 242 if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_STRING) {
249 sway_log(L_ERROR, "Relpy type incorrect"); 243 sway_log(L_ERROR, "Icon name relpy type incorrect");
250 sway_log(L_ERROR, "Should be \"s\", is \"%s\"",
251 dbus_message_iter_get_signature(&iter));
252 goto bail; 244 goto bail;
253 } 245 }
254 246
diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c
index 924ff1a0..f1ecb429 100644
--- a/swaybar/tray/tray.c
+++ b/swaybar/tray/tray.c
@@ -131,7 +131,7 @@ static void get_obj_items_reply(DBusPendingCall *pending, void *_data) {
131 goto bail; 131 goto bail;
132 } 132 }
133 dbus_message_iter_recurse(&iter, &variant); 133 dbus_message_iter_recurse(&iter, &variant);
134 if (strcmp(dbus_message_iter_get_signature(&variant), "a(os)") != 0) { 134 if (dbus_message_iter_check_signature(&iter, "a(os)")) {
135 sway_log(L_ERROR, "Replyed with wrong type not a(os)"); 135 sway_log(L_ERROR, "Replyed with wrong type not a(os)");
136 goto bail; 136 goto bail;
137 } 137 }