From c2bf8c920ea33dc34b775de7bf55977e8cd1e347 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 5 May 2026 17:09:12 +0200 Subject: [PATCH] protocol-native: close fd and unset env in all cases If we find the fd valid, we must attempt to close it. Also unset the env variable when we read and processed it, even if there was an error. --- src/modules/module-protocol-native.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 323468524..91acfc976 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -841,7 +841,7 @@ close_data(void *data, int fd, uint32_t mask) static int write_socket_address(struct server *s) { long v; - int fd, res = 0; + int fd, res; char *endptr; const char *env = getenv("PIPEWIRE_NOTIFICATION_FD"); @@ -855,24 +855,25 @@ static int write_socket_address(struct server *s) if (errno != 0) { res = -errno; pw_log_error("server %p: strtol() failed with error: %m", s); - goto error; + goto exit; } fd = (int)v; - if (v != fd) { + if (fd < 0 || v != fd) { res = -ERANGE; pw_log_error("server %p: invalid fd %ld: %s", s, v, spa_strerror(res)); - goto error; + goto exit; } if (dprintf(fd, "%s\n", s->addr.sun_path) < 0) { res = -errno; pw_log_error("server %p: dprintf() failed with error: %m", s); - goto error; + goto exit_close; } - close(fd); - unsetenv("PIPEWIRE_NOTIFICATION_FD"); - return 0; + res = 0; -error: +exit_close: + close(fd); +exit: + unsetenv("PIPEWIRE_NOTIFICATION_FD"); return res; }