From bill@twwells.com  Wed Jul  4 00:26:09 2001
Return-Path: <bill@twwells.com>
Received: from smtp.popsite.net (smtp.popsite.net [216.126.128.16])
	by hub.freebsd.org (Postfix) with ESMTP id CB3EB37B407
	for <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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: <E15Hh2o-000BfA-00@twwells.com>
Date: Wed, 04 Jul 2001 03:25:54 -0400
From: "T. William Wells" <bill@twwells.com>
Reply-To: bill@twwells.com
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] camlib.c: cam_real_open_device fd leak
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         28688
>Category:       bin
>Synopsis:       [PATCH] camlib.c: cam_real_open_device fd leak
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mjacob
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 04 00:30:07 PDT 2001
>Closed-Date:    Tue Jul 24 16:09:18 PDT 2001
>Last-Modified:  Tue Jul 24 16:09:37 PDT 2001
>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:
Responsible-Changed-From-To: freebsd-bugs->mjacob 
Responsible-Changed-By: mjacob 
Responsible-Changed-When: Wed Jul 4 00:31:35 PDT 2001 
Responsible-Changed-Why:  
I'll field it 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28688 
State-Changed-From-To: open->closed 
State-Changed-By: mjacob 
State-Changed-When: Tue Jul 24 16:09:18 PDT 2001 
State-Changed-Why:  
Fixed in -current ant RELENG_4. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28688 
>Unformatted:
