From 7e58050590c556643869a1cc57215026ff88b0db Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Thu, 1 Dec 2011 11:44:21 +0200 Subject: proto: Use .priv_data_size to allocate the private context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This simplifies the open functions by avoiding one function call that needs error checking, reducing the amount of extra bulk code. Signed-off-by: Martin Storsjö --- libavformat/udp.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'libavformat/udp.c') diff --git a/libavformat/udp.c b/libavformat/udp.c index 178cef477a..529114a860 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -306,7 +306,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) { char hostname[1024], localaddr[1024] = ""; int port, udp_fd = -1, tmp, bind_ret = -1; - UDPContext *s = NULL; + UDPContext *s = h->priv_data; int is_output; const char *p; char buf[256]; @@ -319,11 +319,6 @@ static int udp_open(URLContext *h, const char *uri, int flags) is_output = !(flags & AVIO_FLAG_READ); - s = av_mallocz(sizeof(UDPContext)); - if (!s) - return AVERROR(ENOMEM); - - h->priv_data = s; s->ttl = 16; s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE; @@ -440,7 +435,6 @@ static int udp_open(URLContext *h, const char *uri, int flags) fail: if (udp_fd >= 0) closesocket(udp_fd); - av_free(s); return AVERROR(EIO); } @@ -486,7 +480,6 @@ static int udp_close(URLContext *h) if (s->is_multicast && (h->flags & AVIO_FLAG_READ)) udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); closesocket(s->udp_fd); - av_free(s); return 0; } @@ -497,4 +490,5 @@ URLProtocol ff_udp_protocol = { .url_write = udp_write, .url_close = udp_close, .url_get_file_handle = udp_get_file_handle, + .priv_data_size = sizeof(UDPContext), }; -- cgit v1.2.3