From archie@whistle.com  Tue Feb  3 13:15:35 1998
Received: from whistle.com (s205m131.whistle.com [207.76.205.131])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA05285
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 3 Feb 1998 13:15:31 -0800 (PST)
          (envelope-from archie@whistle.com)
Received: (from smap@localhost) by whistle.com (8.7.5/8.6.12) id NAA08262 for <FreeBSD-gnats-submit@freebsd.org>; Tue, 3 Feb 1998 13:06:00 -0800 (PST)
Received: from bubba.whistle.com(207.76.205.7) by whistle.com via smap (V1.3)
	id sma008260; Tue Feb  3 13:05:48 1998
Received: (from archie@localhost) by bubba.whistle.com (8.8.7/8.6.12) id NAA19000; Tue, 3 Feb 1998 13:05:48 -0800 (PST)
Message-Id: <199802032105.NAA19000@bubba.whistle.com>
Date: Tue, 3 Feb 1998 13:05:48 -0800 (PST)
From: archie@whistle.com
Reply-To: archie@whistle.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: line discipline is not unloaded when device closes
X-Send-Pr-Version: 3.2

>Number:         5636
>Category:       kern
>Synopsis:       line discipline is not unloaded when device closes
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb  3 13:20:01 PST 1998
>Closed-Date:    Wed Feb 4 01:27:12 PST 1998
>Last-Modified:  Wed Feb  4 01:29:22 PST 1998
>Originator:     Archie Cobbs
>Release:        FreeBSD 2.2.5-STABLE i386
>Organization:
Whistle Communications, Inc.
>Environment:

	FreeBSD 2.2.5

>Description:

	I have written a line discipline module. I have a test program
	that shows it successfully loads using ioctl(fd, TIOCSETD, &ldisc).

	The "open" method gets called upon installation, and if the
	line discipline is changed back to TTYDISC, the "close" method
	gets called.

	The problem is that if the device is closed after installing the
	new line discipline, but before reinstalling TTYDISC, the "close"
	method does NOT get called. This can cause memory leaks, dangling
	pointers, etc.

From /sys/sys/conf.h:

	/*
	 * Line discipline switch table
	 */
	struct linesw {
		l_open_t        *l_open;	<-- open method
		l_close_t       *l_close;	<-- close method
		l_read_t        *l_read;
		l_write_t       *l_write;
		l_ioctl_t       *l_ioctl;
		l_rint_t        *l_rint;
		l_start_t       *l_start;
		l_modem_t       *l_modem;
	};

>How-To-Repeat:

	1. Register your own line discipline as #7

	2. Install it with a program containing these lines:

	  ldisc = 7;
	  if ((fd = open(file, O_RDWR, 0)) < 0) {
	    err(1, "%s", file);
	  }
	  if (ioctl(fd, TIOCSETD, &ldisc) < 0) {
	    err(1, "ioctl(TIOCSETD)"); 
	  }
	  sleep(10000);

	3. Hit control-C during the sleep() statement

	4. Notice that the "close" method of your line discipline
	   never gets called.

>Fix:

	Kernel should insure that when a tty device is closed, the
	"close" method of the corresponding line discipline is called.

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: bde 
State-Changed-When: Wed Feb 4 01:27:12 PST 1998 
State-Changed-Why:  
Closed at the submitter's request.  The bug was imaginary. 
>Unformatted:
