Skip to content

Commit 093e94e

Browse files
Sven PüschelSven Püschel
authored andcommitted
wayland: improve deinit and init
Improve the wayland deinit and init process to fix problems after running deinit followed by init in case of a reload. Furthermore destroy otherwise leaked objects and clear associated pointers to prevent potential use after free bugs. This change fixes dunst from breaking sometimes, when a reload is triggered while a notification is displayed. This issue happed because of either ctx.dirty not being cleared, which causes an set_dirty to do an early exit without scheduling a frame to the surface. Or because the frame_callback was not being cleared, which prevented further surface commits, as the callback would never be triggered after the surface was destroyed by the deinit process. Fixes #1434
1 parent ad210bb commit 093e94e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/wayland/wl.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ static const struct wl_registry_listener registry_listener = {
220220
};
221221

222222
bool wl_init(void) {
223+
ctx.dirty = false;
223224
wl_list_init(&ctx.outputs);
224225
wl_list_init(&ctx.seats);
225226
wl_list_init(&toplevel_list);
@@ -334,11 +335,15 @@ void wl_deinit(void) {
334335
if (ctx.layer_surface != NULL) {
335336
g_clear_pointer(&ctx.layer_surface, zwlr_layer_surface_v1_destroy);
336337
}
338+
if (ctx.frame_callback) {
339+
g_clear_pointer(&ctx.frame_callback, wl_callback_destroy);
340+
}
337341
if (ctx.surface != NULL) {
338342
g_clear_pointer(&ctx.surface, wl_surface_destroy);
339343
}
340344
finish_buffer(&ctx.buffers[0]);
341345
finish_buffer(&ctx.buffers[1]);
346+
ctx.current_buffer = NULL;
342347

343348
// The output list is initialized at the start of init, so no need to
344349
// check for NULL
@@ -383,10 +388,20 @@ void wl_deinit(void) {
383388
if (ctx.cursor_theme != NULL) {
384389
g_clear_pointer(&ctx.cursor_theme, wl_cursor_theme_destroy);
385390
g_clear_pointer(&ctx.cursor_surface, wl_surface_destroy);
391+
ctx.cursor_image = NULL;
392+
}
393+
394+
if (ctx.toplevel_manager) {
395+
zwlr_foreign_toplevel_manager_v1_stop(ctx.toplevel_manager);
396+
g_clear_pointer(&ctx.toplevel_manager, zwlr_foreign_toplevel_manager_v1_destroy);
397+
// Set it to the default initialization value instead to UINT32_MAX
398+
// (the latter is used on initialization to mark a bad value)
399+
ctx.toplevel_manager_name = 0;
386400
}
387401

388402
// this also disconnects the wl_display
389403
g_clear_pointer(&ctx.esrc, g_water_wayland_source_free);
404+
ctx.display = NULL;
390405
}
391406

392407
static void schedule_frame_and_commit(void);

0 commit comments

Comments
 (0)