[FFmpeg-devel] [PATCH] tcp.c/udp.c memleak?

Michael Niedermayer michaelni
Sat Aug 23 20:27:45 CEST 2008


On Sat, Aug 23, 2008 at 01:50:35PM -0400, Ronald S. Bultje wrote:
> Hi,
> 
> patch#2 removes the fail: case from all cases where it failes before
> socket(), since these do nothing but return. This gives more control
> over the specific return value, e.g. I can change it into EINVAL
> instead of EIO for these cases where it fails because of invalid
> parameters instead of I/O errors.
> 
> The patch also removes the if (fd ...) check because it is no longer
> needed, fail: is only reached when the socket has been created.
> 
> Ronald

> Index: ffmpeg-svn/libavformat/tcp.c
> ===================================================================
> --- ffmpeg-svn.orig/libavformat/tcp.c	2008-08-23 13:44:49.000000000 -0400
> +++ ffmpeg-svn/libavformat/tcp.c	2008-08-23 13:48:34.000000000 -0400
> @@ -46,19 +46,20 @@
>  
>      url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
>        &port, path, sizeof(path), uri);
> -    if (strcmp(proto,"tcp")) goto fail;
> +    if (strcmp(proto,"tcp"))
> +        return AVERROR(EINVAL);
>  
>      if (port <= 0 || port >= 65536)
> -        goto fail;
> +        return AVERROR(EINVAL);
>  
>      dest_addr.sin_family = AF_INET;
>      dest_addr.sin_port = htons(port);
>      if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
> -        goto fail;
> +        return AVERROR(EIO);
>  
>      fd = socket(AF_INET, SOCK_STREAM, 0);
>      if (fd < 0)
> -        goto fail;
> +        return AVERROR(EIO);
>      ff_socket_nonblock(fd, 1);
>  
>   redo:

ok


> @@ -104,7 +105,6 @@
>   fail:
>      ret = AVERROR(EIO);
>   fail1:
> -    if (fd >= 0)
>          closesocket(fd);
>      return ret;
>  }

I have a bad feeling about this
its easy to add a new goto fail and forget that there is no check for fd


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080823/41d34f34/attachment.pgp>



More information about the ffmpeg-devel mailing list