You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Ian Reilly <iw...@yahoo.com> on 2005/10/26 15:32:38 UTC

[PATCH] SyslogAppender leaks sockets

The attached patch for version 1.2.12 fixes two problems in org.apache.log4j.net.SyslogAppender.  First, it doesn't close the writer and as a result leaks UDP sockets.  Second, when logging an exception, it assumes that all lines after the first line start with a \t character.  If this is not the case, it removes the first character from the line (or throws an exception if the line is empty).
 
 


		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.  

Re: [PATCH] SyslogAppender leaks sockets

Posted by Mark Womack <mw...@apache.org>.
Ian, can you please submit this patch as a bug report?  That way we won't
lose track of it.

And thanks for the submission!

-Mark

On 10/26/05, Ian Reilly <iw...@yahoo.com> wrote:
>
> The attached patch for version 1.2.12 fixes two problems in
> org.apache.log4j.net.SyslogAppender.  First, it doesn't close the writer
> and as a result leaks UDP sockets.  Second, when logging an exception, it
> assumes that all lines after the first line start with a \t character.  If
> this is not the case, it removes the first character from the line (or
> throws an exception if the line is empty).
>
>
>
> ------------------------------
> Yahoo! FareChase - Search multiple travel sites in one click.<http://www.google.com/url?sa=D&q=http%3A%2F%2Fus.lrd.yahoo.com%2F_ylc%3DX3oDMTFqODRtdXQ4BF9TAzMyOTc1MDIEX3MDOTY2ODgxNjkEcG9zAzEEc2VjA21haWwtZm9vdGVyBHNsawNmYw--%2FSIG%3D110oav78o%2F**http%253a%2F%2Ffarechase.yahoo.com%2F>
>
>
> --- SyslogAppender.java.orig    2005-10-25 15:50:35.000000000 -0400
> +++ SyslogAppender.java 2005-10-25 15:19:57.000000000 -0400
> @@ -121,8 +121,11 @@
>   public
>   void close() {
>     closed = true;
> -    // A SyslogWriter is UDP based and needs no opening. Hence, it
> -    // can't be closed. We just unset the variables here.
> +    try {
> +       if (sqw != null) sqw.close();
> +    } catch (Exception e) {
> +       // ignore error
> +    }
>     sqw = null;
>   }
>
> @@ -260,7 +263,15 @@
>         if(len > 0) {
>           sqw.write(s[0]);
>           for(int i = 1; i < len; i++) {
> -            sqw.write(TAB+s[i].substring(1));
> +            if (s[i].length() > 0) {
> +               if (s[i].charAt(0) == '\t') {
> +                  sqw.write(TAB+s[i].substring(1));
> +               } else {
> +                  sqw.write(TAB+s[i]);
> +               }
> +            } else {
> +               sqw.write(s[i]);
> +            }
>           }
>         }
>       }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>