From bb5e2d3f56a994b42a84678661bbc097709c890b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 24 Feb 2009 12:11:00 +0100 Subject: [PATCH] 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. --- gst-libs/gst/rtsp/gstrtspconnection.c | 69 +++++++++++++-------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/gst-libs/gst/rtsp/gstrtspconnection.c b/gst-libs/gst/rtsp/gstrtspconnection.c index a102a0cf2d..f861d8aa23 100644 --- a/gst-libs/gst/rtsp/gstrtspconnection.c +++ b/gst-libs/gst/rtsp/gstrtspconnection.c @@ -199,9 +199,23 @@ GstRTSPResult gst_rtsp_connection_create (GstRTSPUrl * url, GstRTSPConnection ** conn) { GstRTSPConnection *newconn; +#ifdef G_OS_WIN32 + WSADATA w; + int error; +#endif 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); if ((newconn->fdset = gst_poll_new (TRUE)) == NULL) @@ -222,9 +236,26 @@ gst_rtsp_connection_create (GstRTSPUrl * url, GstRTSPConnection ** conn) return GST_RTSP_OK; /* 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: { g_free (newconn); +#ifdef G_OS_WIN32 + WSACleanup (); +#endif return GST_RTSP_ESYS; } } @@ -865,24 +896,9 @@ gst_rtsp_connection_send (GstRTSPConnection * conn, GstRTSPMessage * message, GString *str = NULL; 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 (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))) goto no_message; @@ -899,20 +915,6 @@ no_message: g_warning ("Wrong message"); 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 @@ -1429,9 +1431,6 @@ gst_rtsp_connection_close (GstRTSPConnection * conn) gst_poll_remove_fd (conn->fdset, &conn->fd); res = CLOSE_SOCKET (conn->fd.fd); conn->fd.fd = -1; -#ifdef G_OS_WIN32 - WSACleanup (); -#endif if (res != 0) goto sys_error; } @@ -1461,14 +1460,14 @@ gst_rtsp_connection_free (GstRTSPConnection * conn) res = gst_rtsp_connection_close (conn); gst_poll_free (conn->fdset); -#ifdef G_OS_WIN32 - WSACleanup (); -#endif g_timer_destroy (conn->timer); g_free (conn->username); g_free (conn->passwd); gst_rtsp_connection_clear_auth_params (conn); g_free (conn); +#ifdef G_OS_WIN32 + WSACleanup (); +#endif return res; }