From 701a352e7eb03f5daf4252ea0a0f7aa437819b71 Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Thu, 29 Oct 2026 08:35:02 +0000 Subject: main: don't abort when an image path expands to no words An expansion can yield no words (e.g. -i '' or an unset variable), which made join_args() assert and swaylock abort before locking. Use an empty path in that case, so loading it fails normally and swaylock carries on and locks, instead of falling back to the unexpanded string. Also free path and output_name on the failed-load return. --- main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 27ac27b..e1c4f62 100644 --- a/main.c +++ b/main.c @@ -383,14 +383,20 @@ static void load_image(char *arg, struct swaylock_state *state) { *ptr = '\\'; } if (wordexp(image->path, &p, 0) == 0) { + // An expansion can yield no words (e.g. an empty or unset variable). + // Use an empty path then: loading it fails below, without falling + // back to the unexpanded string. free(image->path); - image->path = join_args(p.we_wordv, p.we_wordc); + image->path = p.we_wordc > 0 ? + join_args(p.we_wordv, p.we_wordc) : strdup(""); wordfree(&p); } // Load the actual image image->cairo_surface = load_background_image(image->path); if (!image->cairo_surface) { + free(image->output_name); + free(image->path); free(image); return; } -- cgit v1.2.3