From aa69ed81b558f74e470e69cdcd442f9048ee624c Mon Sep 17 00:00:00 2001
From: korei999 <ju7t1xe@gmail.com>
Date: Sun, 2 Feb 2025 01:38:47 +0200
Subject: allocate with LISTEN_STATIC

Fixes: https://codeberg.org/dwl/dwl/issues/723
Supersedes: https://codeberg.org/dwl/dwl/pulls/724
---
 dwl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/dwl.c b/dwl.c
index ad21e1b..ec4ca86 100644
--- a/dwl.c
+++ b/dwl.c
@@ -79,7 +79,7 @@
 #define END(A)                  ((A) + LENGTH(A))
 #define TAGMASK                 ((1u << TAGCOUNT) - 1)
 #define LISTEN(E, L, H)         wl_signal_add((E), ((L)->notify = (H), (L)))
-#define LISTEN_STATIC(E, H)     do { static struct wl_listener _l = {.notify = (H)}; wl_signal_add((E), &_l); } while (0)
+#define LISTEN_STATIC(E, H)     do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0)
 
 /* enums */
 enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
@@ -906,6 +906,7 @@ commitpopup(struct wl_listener *listener, void *data)
 	box.y -= (type == LayerShell ? l->scene->node.y : c->geom.y);
 	wlr_xdg_popup_unconstrain_from_box(popup, &box);
 	wl_list_remove(&listener->link);
+	free(listener);
 }
 
 void
@@ -1246,6 +1247,7 @@ destroydragicon(struct wl_listener *listener, void *data)
 	focusclient(focustop(selmon), 1);
 	motionnotify(0, NULL, 0, 0, 0, 0);
 	wl_list_remove(&listener->link);
+	free(listener);
 }
 
 void
@@ -1255,6 +1257,7 @@ destroyidleinhibitor(struct wl_listener *listener, void *data)
 	 * at this point the idle inhibitor is still in the list of the manager */
 	checkidleinhibitor(wlr_surface_get_root_surface(data));
 	wl_list_remove(&listener->link);
+	free(listener);
 }
 
 void
-- 
cgit v1.2.3