# HG changeset patch # User rbultje # Date 1219517190 0 # Node ID 8d267b43eaba04bdf8ceddcb3543c40b4148fd15 # Parent 42ed3629601d82c45c8a52e7801e742221bfb61f 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. diff -r 42ed3629601d -r 8d267b43eaba tcp.c --- a/tcp.c Sat Aug 23 17:39:56 2008 +0000 +++ b/tcp.c Sat Aug 23 18:46:30 2008 +0000 @@ -49,12 +49,6 @@ 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 @@ 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 @@ fail1: if (fd >= 0) closesocket(fd); - av_free(s); return ret; }