[pulseaudio-discuss] [PATCH] socket-server: pa_socket_server_new() can't fail, so don't check its return value

Alexander E. Patrakov patrakov at gmail.com
Mon Dec 29 07:10:35 PST 2014


03.11.2014 14:47, Tanu Kaskinen wrote:
> An assertion was already used in pa_socket_server_new_unix(), this
> makes the TCP variants consistent with that.
>
> Even if pa_socket_server_new() could fail, the error handling wasn't
> good, because there was no "goto fail", meaning that the fd would have
> been leaked.

The patch looks OK. However, the pa_socket_server_new() function is only 
used in the same file, so maybe it is a good idea to also make it static?

> ---
>   src/pulsecore/socket-server.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/src/pulsecore/socket-server.c b/src/pulsecore/socket-server.c
> index 25a2f8a..7c513cb 100644
> --- a/src/pulsecore/socket-server.c
> +++ b/src/pulsecore/socket-server.c
> @@ -275,10 +275,10 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
>           goto fail;
>       }
>
> -    if ((ss = pa_socket_server_new(m, fd))) {
> -        ss->type = SOCKET_SERVER_IPV4;
> -        ss->tcpwrap_service = pa_xstrdup(tcpwrap_service);
> -    }
> +    pa_assert_se(ss = pa_socket_server_new(m, fd));
> +
> +    ss->type = SOCKET_SERVER_IPV4;
> +    ss->tcpwrap_service = pa_xstrdup(tcpwrap_service);
>
>       return ss;
>
> @@ -343,10 +343,10 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
>           goto fail;
>       }
>
> -    if ((ss = pa_socket_server_new(m, fd))) {
> -        ss->type = SOCKET_SERVER_IPV6;
> -        ss->tcpwrap_service = pa_xstrdup(tcpwrap_service);
> -    }
> +    pa_assert_se(ss = pa_socket_server_new(m, fd));
> +
> +    ss->type = SOCKET_SERVER_IPV6;
> +    ss->tcpwrap_service = pa_xstrdup(tcpwrap_service);
>
>       return ss;
>
>

-- 
Alexander E. Patrakov


More information about the pulseaudio-discuss mailing list