changeset 3753:42ed3629601d libavformat

Fix memleak on some OSes in case network initialization fails. See "[PATCH] tcp.c/udp.c memleak?" for discussion.
author rbultje
date Sat, 23 Aug 2008 17:39:56 +0000
parents 4ef51601582d
children 8d267b43eaba
files tcp.c udp.c
diffstat 2 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/tcp.c	Sat Aug 23 17:39:10 2008 +0000
+++ b/tcp.c	Sat Aug 23 17:39:56 2008 +0000
@@ -41,6 +41,9 @@
     socklen_t optlen;
     char proto[1024],path[1024],tmp[1024];
 
+    if(!ff_network_init())
+        return AVERROR(EIO);
+
     url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
       &port, path, sizeof(path), uri);
     if (strcmp(proto,"tcp")) goto fail;
@@ -55,9 +58,6 @@
     if (port <= 0 || port >= 65536)
         goto fail;
 
-    if(!ff_network_init())
-        return AVERROR(EIO);
-
     dest_addr.sin_family = AF_INET;
     dest_addr.sin_port = htons(port);
     if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
--- a/udp.c	Sat Aug 23 17:39:10 2008 +0000
+++ b/udp.c	Sat Aug 23 17:39:56 2008 +0000
@@ -348,6 +348,9 @@
 
     is_output = (flags & URL_WRONLY);
 
+    if(!ff_network_init())
+        return AVERROR(EIO);
+
     s = av_mallocz(sizeof(UDPContext));
     if (!s)
         return AVERROR(ENOMEM);
@@ -380,9 +383,6 @@
         udp_set_remote_url(h, uri);
     }
 
-    if(!ff_network_init())
-        return AVERROR(EIO);
-
     if (s->is_multicast && !(h->flags & URL_WRONLY))
         s->local_port = port;
     udp_fd = udp_socket_create(s, &my_addr, &len);