summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonald S. Bultje <rsbultje@gmail.com>2008-08-23 18:46:30 +0000
committerRonald S. Bultje <rsbultje@gmail.com>2008-08-23 18:46:30 +0000
commit47f944a2efea1af48d2f47df25ee92386dbd8491 (patch)
tree18a39f92997407d5c3e0db8e3e43be5343c1ec49
parente6c13819825aab796965a96ffb451cd008eab647 (diff)
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. Originally committed as revision 14924 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/tcp.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 9191960ca7..470d0ce8d1 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -49,12 +49,6 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
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 char *uri, int flags)
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 char *uri, int flags)
fail1:
if (fd >= 0)
closesocket(fd);
- av_free(s);
return ret;
}