mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
Match WSAStartup and WSACleanup correctly
Don't randomly call WSAStartup and WSACleanup but instead call the startup when we create a connection and cleanup when we free it again. Because the internal datastructure is refcounted, this should not cause any refcounting leaks when the connection is managed correctly. Fixes #562794.
This commit is contained in:
parent
bbd66c6baf
commit
bb5e2d3f56
1 changed files with 34 additions and 35 deletions
|
@ -199,9 +199,23 @@ GstRTSPResult
|
||||||
gst_rtsp_connection_create (GstRTSPUrl * url, GstRTSPConnection ** conn)
|
gst_rtsp_connection_create (GstRTSPUrl * url, GstRTSPConnection ** conn)
|
||||||
{
|
{
|
||||||
GstRTSPConnection *newconn;
|
GstRTSPConnection *newconn;
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
WSADATA w;
|
||||||
|
int error;
|
||||||
|
#endif
|
||||||
|
|
||||||
g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
|
g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
|
||||||
|
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
error = WSAStartup (0x0202, &w);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
goto startup_error;
|
||||||
|
|
||||||
|
if (w.wVersion != 0x0202)
|
||||||
|
goto version_error;
|
||||||
|
#endif
|
||||||
|
|
||||||
newconn = g_new0 (GstRTSPConnection, 1);
|
newconn = g_new0 (GstRTSPConnection, 1);
|
||||||
|
|
||||||
if ((newconn->fdset = gst_poll_new (TRUE)) == NULL)
|
if ((newconn->fdset = gst_poll_new (TRUE)) == NULL)
|
||||||
|
@ -222,9 +236,26 @@ gst_rtsp_connection_create (GstRTSPUrl * url, GstRTSPConnection ** conn)
|
||||||
return GST_RTSP_OK;
|
return GST_RTSP_OK;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
startup_error:
|
||||||
|
{
|
||||||
|
g_warning ("Error %d on WSAStartup", error);
|
||||||
|
return GST_RTSP_EWSASTART;
|
||||||
|
}
|
||||||
|
version_error:
|
||||||
|
{
|
||||||
|
g_warning ("Windows sockets are not version 0x202 (current 0x%x)",
|
||||||
|
w.wVersion);
|
||||||
|
WSACleanup ();
|
||||||
|
return GST_RTSP_EWSAVERSION;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
no_fdset:
|
no_fdset:
|
||||||
{
|
{
|
||||||
g_free (newconn);
|
g_free (newconn);
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
WSACleanup ();
|
||||||
|
#endif
|
||||||
return GST_RTSP_ESYS;
|
return GST_RTSP_ESYS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -865,24 +896,9 @@ gst_rtsp_connection_send (GstRTSPConnection * conn, GstRTSPMessage * message,
|
||||||
GString *str = NULL;
|
GString *str = NULL;
|
||||||
GstRTSPResult res;
|
GstRTSPResult res;
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
WSADATA w;
|
|
||||||
int error;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
|
g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
|
||||||
g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
|
g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
error = WSAStartup (0x0202, &w);
|
|
||||||
|
|
||||||
if (error)
|
|
||||||
goto startup_error;
|
|
||||||
|
|
||||||
if (w.wVersion != 0x0202)
|
|
||||||
goto version_error;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!(str = message_to_string (conn, message)))
|
if (!(str = message_to_string (conn, message)))
|
||||||
goto no_message;
|
goto no_message;
|
||||||
|
|
||||||
|
@ -899,20 +915,6 @@ no_message:
|
||||||
g_warning ("Wrong message");
|
g_warning ("Wrong message");
|
||||||
return GST_RTSP_EINVAL;
|
return GST_RTSP_EINVAL;
|
||||||
}
|
}
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
startup_error:
|
|
||||||
{
|
|
||||||
g_warning ("Error %d on WSAStartup", error);
|
|
||||||
return GST_RTSP_EWSASTART;
|
|
||||||
}
|
|
||||||
version_error:
|
|
||||||
{
|
|
||||||
g_warning ("Windows sockets are not version 0x202 (current 0x%x)",
|
|
||||||
w.wVersion);
|
|
||||||
WSACleanup ();
|
|
||||||
return GST_RTSP_EWSAVERSION;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1429,9 +1431,6 @@ gst_rtsp_connection_close (GstRTSPConnection * conn)
|
||||||
gst_poll_remove_fd (conn->fdset, &conn->fd);
|
gst_poll_remove_fd (conn->fdset, &conn->fd);
|
||||||
res = CLOSE_SOCKET (conn->fd.fd);
|
res = CLOSE_SOCKET (conn->fd.fd);
|
||||||
conn->fd.fd = -1;
|
conn->fd.fd = -1;
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
WSACleanup ();
|
|
||||||
#endif
|
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
goto sys_error;
|
goto sys_error;
|
||||||
}
|
}
|
||||||
|
@ -1461,14 +1460,14 @@ gst_rtsp_connection_free (GstRTSPConnection * conn)
|
||||||
|
|
||||||
res = gst_rtsp_connection_close (conn);
|
res = gst_rtsp_connection_close (conn);
|
||||||
gst_poll_free (conn->fdset);
|
gst_poll_free (conn->fdset);
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
WSACleanup ();
|
|
||||||
#endif
|
|
||||||
g_timer_destroy (conn->timer);
|
g_timer_destroy (conn->timer);
|
||||||
g_free (conn->username);
|
g_free (conn->username);
|
||||||
g_free (conn->passwd);
|
g_free (conn->passwd);
|
||||||
gst_rtsp_connection_clear_auth_params (conn);
|
gst_rtsp_connection_clear_auth_params (conn);
|
||||||
g_free (conn);
|
g_free (conn);
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
WSACleanup ();
|
||||||
|
#endif
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue