From 2bd4f4d31101d92586e54bdfba770e834f1466d3 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Wed, 24 Jun 2026 17:48:58 +0200 Subject: [PATCH] MT#61856 media_socket: init fd to -1 when binding socket When binding the port to a socket, init fd to -1 because 0 is actually a valid id for fd in the system, this `struct socket_port_link spl = {0};` puts `.fd = 0` and if socket binding fails, then `.fd == 0` which is a totally valid fd. Instead init it to -1 and then let `add_socket()` to actually fill the structure's data properly, if however that one fails to bind, then again return `.fd = -1`. Change-Id: Iaeeee534a66b43441253ddfe710c8163084ad444 --- daemon/media_socket.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 053d9db62..d04c64dbe 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1225,9 +1225,12 @@ struct socket_port_link get_specific_port(unsigned int port, { if (!port_is_in_range(&spec->port_pool, port)) { ilog(LOG_DEBUG, "A specific out-of-pool port is requested: '%d'", port); - struct socket_port_link spl = {0}; - add_socket(&spl.socket, port, spec, label); - return spl; + + struct socket_port_link spl = { .socket = { .fd = -1 } }; + if (add_socket(&spl.socket, port, spec, label)) + return spl; + + return (struct socket_port_link) { .socket = { .fd = -1 } }; } ilog(LOG_DEBUG, "A specific in-pool port is requested: '%d'", port);