On Fri, Nov 01, 2024 at 06:47:52AM -0700, Steve Sistare wrote:
> +void qtest_connect_deferred(QTestState *s)
> +{
> +    g_autofree gchar *socket_path = NULL;
> +    g_autofree gchar *qmp_socket_path = NULL;
> +
> +    socket_path = g_strdup_printf("%s/qtest-%d.sock",
> +                                  g_get_tmp_dir(), getpid());
> +    qmp_socket_path = g_strdup_printf("%s/qtest-%d.qmp",
> +                                      g_get_tmp_dir(), getpid());
> +
> +    s->fd = socket_accept(s->sock);
> +    if (s->fd >= 0) {
> +        s->qmp_fd = socket_accept(s->qmpsock);
> +    }
> +    unlink(socket_path);
> +    unlink(qmp_socket_path);

Why need to unlink again here if both sock/qmpsock are cached?  I assume we
could remove these lines together with above g_strdup_printf()s.

Otherwise two paths are leaked anyway (and we may also want to have some
macros to represent the paths used in two places).

Maybe we could also clear sock/qmpsock too after use, then check at the
entrance to skip qtest_connect_deferred() if already connected.

> +    g_assert(s->fd >= 0 && s->qmp_fd >= 0);
>      /* ask endianness of the target */
> -
>      s->big_endian = qtest_query_target_endianness(s);
> -
> -   return s;
>  }

-- 
Peter Xu


Reply via email to