remote: always close the fd in connect_fd

Not closing the fd causes leaks in existing apps. It's probably better
to always close it and let apps deal with that by using dup or similar.

Make gst sink and source dup the fd before connect_fd().

Fixes #181
This commit is contained in:
Wim Taymans 2019-09-10 11:05:38 +02:00
parent 633c27824f
commit 9a202272f2
4 changed files with 5 additions and 4 deletions

View file

@ -36,6 +36,7 @@
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include "gstpipewireformat.h"
@ -735,7 +736,7 @@ gst_pipewire_sink_open (GstPipeWireSink * pwsink)
if (pwsink->fd == -1)
pw_remote_connect (pwsink->remote);
else
pw_remote_connect_fd (pwsink->remote, pwsink->fd);
pw_remote_connect_fd (pwsink->remote, dup(pwsink->fd));
while (TRUE) {
enum pw_remote_state state = pw_remote_get_state (pwsink->remote, &error);

View file

@ -1002,7 +1002,7 @@ gst_pipewire_src_open (GstPipeWireSrc * pwsrc)
if (pwsrc->fd == -1)
pw_remote_connect (pwsrc->remote);
else
pw_remote_connect_fd (pwsrc->remote, pwsrc->fd);
pw_remote_connect_fd (pwsrc->remote, dup(pwsrc->fd));
while (TRUE) {
enum pw_remote_state state = pw_remote_get_state(pwsrc->remote, &error);

View file

@ -428,7 +428,7 @@ int pw_remote_connect_fd(struct pw_remote *remote, int fd)
pw_remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL);
if ((res = pw_protocol_client_connect_fd(remote->conn, fd, false)) < 0) {
if ((res = pw_protocol_client_connect_fd(remote->conn, fd, true)) < 0) {
pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR,
"connect_fd failed %s", spa_strerror(res));
return res;

View file

@ -177,7 +177,7 @@ void pw_remote_add_listener(struct pw_remote *remote,
int pw_remote_connect(struct pw_remote *remote);
/** Connect to a remote PipeWire on the given socket \memberof pw_remote
* \param fd the connected socket to use, the socket will not be closed
* \param fd the connected socket to use, the socket will be closed
* automatically on disconnect or error.
* \return 0 on success, < 0 on error */
int pw_remote_connect_fd(struct pw_remote *remote, int fd);