From owner-freebsd-bugs Wed Jul 4 0:30:14 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 035F437B405 for ; Wed, 4 Jul 2001 00:30:08 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.3/8.11.3) id f647U7S90343; Wed, 4 Jul 2001 00:30:07 -0700 (PDT) (envelope-from gnats) Received: from smtp.popsite.net (smtp.popsite.net [216.126.128.16]) by hub.freebsd.org (Postfix) with ESMTP id CB3EB37B407 for ; Wed, 4 Jul 2001 00:26:08 -0700 (PDT) (envelope-from bill@twwells.com) Received: from twwells.com (02-069.051.popsite.net [64.24.21.69]) by smtp.popsite.net (Postfix) with ESMTP id BFB24FEBF for ; Wed, 4 Jul 2001 02:26:04 -0500 (CDT) Received: from bill by twwells.com with local (Exim 3.22 #1) id 15Hh2o-000BfA-00 for FreeBSD-gnats-submit@freebsd.org; Wed, 04 Jul 2001 03:25:54 -0400 Message-Id: Date: Wed, 04 Jul 2001 03:25:54 -0400 From: "T. William Wells" Reply-To: bill@twwells.com To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/28688: [PATCH] camlib.c: cam_real_open_device fd leak Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 28688 >Category: bin >Synopsis: [PATCH] camlib.c: cam_real_open_device fd leak >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jul 04 00:30:07 PDT 2001 >Closed-Date: >Last-Modified: >Originator: T. William Wells >Release: FreeBSD 4.3-STABLE i386 >Organization: >Environment: System: FreeBSD twwells.com 4.3-STABLE FreeBSD 4.3-STABLE #7: Fri May 18 01:15:21 EDT 2001 root@twwells.com:/usr/obj/usr/src/sys/TWWELLS i386 >Description: When one of the various system calls in cam_real_open_device fails after the open, the file descriptor is left open. >How-To-Repeat: Open a non-SCSI device (e.g., /dev/scanner attached to a USB device) and the device will be left open, causing subsequent open attempts to fail. This was observed to happen in SANE's scanimage. >Fix: Apply the following patch: *** camlib.c.orig Wed Jul 4 02:42:31 2001 --- camlib.c Wed Jul 4 02:43:50 2001 *************** *** 554,560 **** char newpath[MAXPATHLEN+1]; char *func_name = "cam_real_open_device"; union ccb ccb; ! int fd, malloced_device = 0; /* * See if the user wants us to malloc a device for him. --- 554,560 ---- char newpath[MAXPATHLEN+1]; char *func_name = "cam_real_open_device"; union ccb ccb; ! int fd = -1, malloced_device = 0; /* * See if the user wants us to malloc a device for him. *************** *** 691,696 **** --- 691,699 ---- crod_bailout: + if (fd >= 0) { + close(fd); + } if (malloced_device) free(device); >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message