You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by df...@apache.org on 2004/09/24 07:03:02 UTC

cvs commit: jakarta-commons/net/src/java/org/apache/commons/net/telnet TelnetClient.java TelnetInputStream.java

dfs         2004/09/23 22:03:01

  Modified:    net/src/java/org/apache/commons/net/telnet TelnetClient.java
                        TelnetInputStream.java
  Log:
  Applied fix for issue
    http://issues.apache.org/bugzilla/show_bug.cgi?id=31272
  reported by Mark Johnson <co...@markj.net>.  The TelnetClient class
  has a setReaderThread that inhibits the starting of the
  TelnetInputStream instance.  However TelnetInputStream creates a
  thread in its constructor, which caused a resource leak when
  readerThread was set to false.  I applied the suggested changes which
  prevent the thread from being created unless explicitly requested.
  
  Revision  Changes    Path
  1.13      +1 -1      jakarta-commons/net/src/java/org/apache/commons/net/telnet/TelnetClient.java
  
  Index: TelnetClient.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/telnet/TelnetClient.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TelnetClient.java	29 Jun 2004 04:54:31 -0000	1.12
  +++ TelnetClient.java	24 Sep 2004 05:03:01 -0000	1.13
  @@ -98,7 +98,7 @@
               input = _input_;
   
   
  -        tmp = new TelnetInputStream(input, this);
  +        tmp = new TelnetInputStream(input, this, readerThread);
           if(readerThread)
           {
               tmp._start();
  
  
  
  1.12      +16 -5     jakarta-commons/net/src/java/org/apache/commons/net/telnet/TelnetInputStream.java
  
  Index: TelnetInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/telnet/TelnetInputStream.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TelnetInputStream.java	29 Feb 2004 10:26:55 -0000	1.11
  +++ TelnetInputStream.java	24 Sep 2004 05:03:01 -0000	1.12
  @@ -50,10 +50,10 @@
       private int __suboption_count = 0;
       /* TERMINAL-TYPE option (end)*/
   
  -    private boolean _ayt_flag = false;
  +    private boolean __threaded;
   
  -    private boolean __threaded = false;
  -    TelnetInputStream(InputStream input, TelnetClient client)
  +    TelnetInputStream(InputStream input, TelnetClient client,
  +                      boolean readerThread)
       {
           super(input);
           __client = client;
  @@ -69,11 +69,22 @@
           __bytesAvailable = 0;
           __ioException = null;
           __readIsWaiting = false;
  -        __thread = new Thread(this);
  +        __threaded = false;
  +        if(__threaded)
  +            __thread = new Thread(this);
  +        else
  +            __thread = null;
  +    }
  +
  +    TelnetInputStream(InputStream input, TelnetClient client) {
  +        this(input, client, true);
       }
   
       void _start()
       {
  +        if(__thread == null)
  +            return;
  +
           int priority;
           __isClosed = false;
           // Need to set a higher priority in case JVM does not use pre-emptive
  @@ -495,7 +506,7 @@
               __hasReachedEOF = true;
               __isClosed      = true;
   
  -            if (__thread.isAlive())
  +            if (__thread != null && __thread.isAlive())
               {
                   __thread.interrupt();
               }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org