[gst-cvs] gst-plugins-base: Match WSAStartup and WSACleanup correctly
Wim Taymans
wtay at kemper.freedesktop.org
Tue Feb 24 03:13:15 PST 2009
Module: gst-plugins-base
Branch: master
Commit: bb5e2d3f56a994b42a84678661bbc097709c890b
URL: http://cgit.freedesktop.org/gstreamer/gst-plugins-base/commit/?id=bb5e2d3f56a994b42a84678661bbc097709c890b
Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date: Tue Feb 24 12:11:00 2009 +0100
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 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/gst-libs/gst/rtsp/gstrtspconnection.c b/gst-libs/gst/rtsp/gstrtspconnection.c
index a102a0c..f861d8a 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;
}
More information about the Gstreamer-commits
mailing list