[FFmpeg-cvslog] r14924 - trunk/libavformat/tcp.c

rbultje subversion
Sat Aug 23 20:46:30 CEST 2008


Author: rbultje
Date: Sat Aug 23 20:46:30 2008
New Revision: 14924

Log:
Move malloc() down until after all initializations, so that the resource is
only allocated if initialization worked. This means that on failure, we
don't have to deallocate it.



Modified:
   trunk/libavformat/tcp.c

Modified: trunk/libavformat/tcp.c
==============================================================================
--- trunk/libavformat/tcp.c	(original)
+++ trunk/libavformat/tcp.c	Sat Aug 23 20:46:30 2008
@@ -49,12 +49,6 @@ static int tcp_open(URLContext *h, const
     if (strcmp(proto,"tcp")) goto fail;
     if ((q = strchr(hostname,'@'))) { strcpy(tmp,q+1); strcpy(hostname,tmp); }
 
-    s = av_malloc(sizeof(TCPContext));
-    if (!s)
-        return AVERROR(ENOMEM);
-    h->priv_data = s;
-    h->is_streamed = 1;
-
     if (port <= 0 || port >= 65536)
         goto fail;
 
@@ -100,6 +94,11 @@ static int tcp_open(URLContext *h, const
         if (ret != 0)
             goto fail;
     }
+    s = av_malloc(sizeof(TCPContext));
+    if (!s)
+        return AVERROR(ENOMEM);
+    h->priv_data = s;
+    h->is_streamed = 1;
     s->fd = fd;
     return 0;
 
@@ -108,7 +107,6 @@ static int tcp_open(URLContext *h, const
  fail1:
     if (fd >= 0)
         closesocket(fd);
-    av_free(s);
     return ret;
 }
 




More information about the ffmpeg-cvslog mailing list