From owner-freebsd-bugs Tue Feb 3 13:20:05 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA06479 for freebsd-bugs-outgoing; Tue, 3 Feb 1998 13:20:05 -0800 (PST) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: (from gnats@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA06430; Tue, 3 Feb 1998 13:20:02 -0800 (PST) (envelope-from gnats) 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 ; 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 ; 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 X-Send-Pr-Version: 3.2 Subject: kern/5636: line discipline is not unloaded when device closes Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org X-To-Unsubscribe: mail to majordomo@FreeBSD.org "unsubscribe freebsd-bugs" >Number: 5636 >Category: kern >Synopsis: line discipline is not unloaded when device closes >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Feb 3 13:20:01 PST 1998 >Last-Modified: >Originator: Archie Cobbs >Organization: Whistle Communications, Inc. >Release: FreeBSD 2.2.5-STABLE i386 >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. >Audit-Trail: >Unformatted: