diff options
author | marcus <marcus@FreeBSD.org> | 2006-04-30 07:02:40 +0000 |
---|---|---|
committer | marcus <marcus@FreeBSD.org> | 2006-04-30 07:02:40 +0000 |
commit | 6e43077eab88e30ef55858fbc7d978f2f9f235dc (patch) | |
tree | 829c529a6b3222fb3272931acdcea660bd9fce61 /lib/libcam | |
parent | 09cd0d923b7a4060f7a1c7405f4eb994a5e7848c (diff) | |
download | FreeBSD-src-6e43077eab88e30ef55858fbc7d978f2f9f235dc.zip FreeBSD-src-6e43077eab88e30ef55858fbc7d978f2f9f235dc.tar.gz |
Fix a file descriptor leak in cam_lookup_pass() when the ioctl to find
the passthru device fails.
Approved by: scottl
MFC after: 1 day
Diffstat (limited to 'lib/libcam')
-rw-r--r-- | lib/libcam/camlib.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/libcam/camlib.c b/lib/libcam/camlib.c index c62d3a6..88191ee 100644 --- a/lib/libcam/camlib.c +++ b/lib/libcam/camlib.c @@ -465,7 +465,7 @@ static struct cam_device * cam_lookup_pass(const char *dev_name, int unit, int flags, const char *given_path, struct cam_device *device) { - int fd; + int fd, rc; union ccb ccb; char dev_path[256]; char *func_name = "cam_lookup_pass"; @@ -494,7 +494,10 @@ cam_lookup_pass(const char *dev_name, int unit, int flags, * the device name is null, if the device doesn't exist, or if the * passthrough driver isn't in the kernel. */ - if (ioctl(fd, CAMGETPASSTHRU, &ccb) == -1) { + rc = ioctl(fd, CAMGETPASSTHRU, &ccb); + close(fd); + + if (rc == -1) { char tmpstr[256]; /* @@ -517,8 +520,6 @@ cam_lookup_pass(const char *dev_name, int unit, int flags, return(NULL); } - close(fd); - /* * If the ioctl returned the right status, but we got an error back * in the ccb, that means that the kernel found the device the user |