diff options
author | Peter Kjellerstedt <pkj@axis.com> | 2008-08-20 11:51:38 +0000 |
---|---|---|
committer | Wim Taymans <wim.taymans@gmail.com> | 2008-08-20 11:51:38 +0000 |
commit | 74314914704609541ca0da9bf1f52469ea5e1079 (patch) | |
tree | 3ddd289bffe323071a6457e0f4d6d91b355c2357 /gst/udp/gstudpsrc.c | |
parent | 0dfa54f45078e349e84772bc57be08bb0c556b47 (diff) |
gst/udp/: Avoid leaking internally allocated file descriptors when setting custom file descriptors. Fixes #543101.
Original commit message from CVS:
Patch by: Peter Kjellerstedt <pkj at axis com>
* gst/udp/gstdynudpsink.c: (gst_dynudpsink_init),
(gst_dynudpsink_finalize), (gst_dynudpsink_set_property),
(gst_dynudpsink_init_send), (gst_dynudpsink_close):
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_init),
(gst_multiudpsink_finalize), (gst_multiudpsink_set_property):
* gst/udp/gstudpsrc.c: (gst_udpsrc_finalize),
(gst_udpsrc_set_property):
Avoid leaking internally allocated file descriptors when setting
custom file descriptors. Fixes #543101.
Diffstat (limited to 'gst/udp/gstudpsrc.c')
-rw-r--r-- | gst/udp/gstudpsrc.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/gst/udp/gstudpsrc.c b/gst/udp/gstudpsrc.c index 586f1d83..ed0dbc0b 100644 --- a/gst/udp/gstudpsrc.c +++ b/gst/udp/gstudpsrc.c @@ -141,13 +141,6 @@ typedef int socklen_t; GST_DEBUG_CATEGORY_STATIC (udpsrc_debug); #define GST_CAT_DEFAULT (udpsrc_debug) -#define CLOSE_IF_REQUESTED(udpctx) \ -G_STMT_START { \ - if ((!udpctx->externalfd) || (udpctx->externalfd && udpctx->closefd)) \ - CLOSE_SOCKET(udpctx->sock.fd); \ - udpctx->sock.fd = -1; \ -} G_STMT_END - static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, @@ -191,6 +184,16 @@ enum PROP_LAST }; +#define CLOSE_IF_REQUESTED(udpctx) \ +G_STMT_START { \ + if ((!udpctx->externalfd) || (udpctx->externalfd && udpctx->closefd)) { \ + CLOSE_SOCKET(udpctx->sock.fd); \ + if (udpctx->sock.fd == udpctx->sockfd) \ + udpctx->sockfd = UDP_DEFAULT_SOCKFD; \ + } \ + udpctx->sock.fd = UDP_DEFAULT_SOCK; \ +} G_STMT_END + static void gst_udpsrc_uri_handler_init (gpointer g_iface, gpointer iface_data); static GstCaps *gst_udpsrc_getcaps (GstBaseSrc * src); @@ -348,7 +351,10 @@ gst_udpsrc_finalize (GObject * object) g_free (udpsrc->multi_group); g_free (udpsrc->uri); - WSA_CLEANUP (src); + if (udpsrc->sockfd >= 0 && udpsrc->closefd) + CLOSE_SOCKET (udpsrc->sockfd); + + WSA_CLEANUP (object); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -671,6 +677,9 @@ gst_udpsrc_set_property (GObject * object, guint prop_id, const GValue * value, break; } case PROP_SOCKFD: + if (udpsrc->sockfd >= 0 && udpsrc->sockfd != udpsrc->sock.fd && + udpsrc->closefd) + CLOSE_SOCKET (udpsrc->sockfd); udpsrc->sockfd = g_value_get_int (value); GST_DEBUG ("setting SOCKFD to %d", udpsrc->sockfd); break; |