On Wed, Mar 02, 2005 at 12:44:03AM +0000, Chris Mason wrote:
> There is a file descriptor leak with clamsmtp that means it will run
> out of file descriptors after a period of time.  By default Linux
> systems have a maximum of 1024 FD's per process and clamsmtp does not
> free file descriptors when an outbound connection is attempted but
> fails.
> 
> After a period of time these file descriptors will eventually run out
> and the process needs to be restarted as it will not accept any new
> connections.
> 
> Upsteam has been aware of this problem for the past couple of weeks,
> but has not emailed me since I reported this problem to him.
> 
> Please find below a patch to fix this issue:
> 
> diff -urN /home/masonc/clamsmtp-1.2/common/spio.c 
> /home/masonc/clamsmtp-1.2-fix/common/spio.c
> --- /home/masonc/clamsmtp-1.2/common/spio.c     2004-11-26 
> 21:22:41.000000000 +0000
> +++ /home/masonc/clamsmtp-1.2-fix/common/spio.c 2005-03-02 
> 00:23:31.000000000 +0000
> @@ -154,8 +154,10 @@
> 
>     fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
> 
> -    if(connect(fd, &SANY_ADDR(*sany), SANY_LEN(*sany)) == -1)
> +    if(connect(fd, &SANY_ADDR(*sany), SANY_LEN(*sany)) == -1) {
> +        close_raw(&fd);
>         RETURN(-1);
> +    }
> 
>     spio_attach(ctx, io, fd, NULL);

OK.  I see.  The file descriptor itself is not -1, so when
spio_valid(io) is called in "cleanup:" and the fd is not -1, it is
assumed the connection was made and the descriptor is not closed.  It
looks like the spio_t wrapper structure needs more stateful information,
and spio_valid(io) needs to be a little more robust.

Your fix would work, but I see what the author was trying to do.  Rather
than calling close_raw(&fd) immediately, he may choose to do something
like:

        io->connected = connect(fd, &...)
        if (io->connected == -1)
                RETURN(-1);

But then again, that's putting a lot of effort into a wrapper structure.
*shrug*  We'll see.  I'll use your patch and see if I can't get him to
talk a bit.

-- 
Chad Walstrom <[EMAIL PROTECTED]>           http://www.wookimus.net/
           assert(expired(knowledge)); /* core dump */

Attachment: signature.asc
Description: Digital signature

Reply via email to