Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/librumpuser Fix fd leak also in non-NetBSD code path.
details: https://anonhg.NetBSD.org/src/rev/ca38ddf15253
branches: trunk
changeset: 760448:ca38ddf15253
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Jan 05 09:43:00 2011 +0000
description:
Fix fd leak also in non-NetBSD code path.
diffstat:
lib/librumpuser/rumpuser.c | 14 ++++++--------
1 files changed, 6 insertions(+), 8 deletions(-)
diffs (77 lines):
diff -r c59fd4570c68 -r ca38ddf15253 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c Wed Jan 05 09:35:51 2011 +0000
+++ b/lib/librumpuser/rumpuser.c Wed Jan 05 09:43:00 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser.c,v 1.11 2011/01/05 00:19:20 wiz Exp $ */
+/* $NetBSD: rumpuser.c,v 1.12 2011/01/05 09:43:00 pooka Exp $ */
/*
* Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved.
@@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.11 2011/01/05 00:19:20 wiz Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.12 2011/01/05 09:43:00 pooka Exp $");
#endif /* !lint */
/* thank the maker for this */
@@ -80,6 +80,7 @@
struct stat sb;
uint64_t size;
int needsdev = 0, rv = 0, ft;
+ int fd = -1;
if (stat(path, &sb) == -1) {
seterror(errno);
@@ -125,7 +126,6 @@
*/
#ifndef __NetBSD__
off_t off;
- int fd;
fd = open(path, O_RDONLY);
if (fd == -1) {
@@ -135,20 +135,18 @@
}
off = lseek(fd, 0, SEEK_END);
- close(fd);
if (off != 0) {
size = off;
goto out;
}
fprintf(stderr, "error: device size query not implemented on "
"this platform\n");
- sererror(EOPNOTSUPP);
+ seterror(EOPNOTSUPP);
rv = -1;
goto out;
#else
struct disklabel lab;
struct partition *parta;
- int fd;
fd = open(path, O_RDONLY);
if (fd == -1) {
@@ -159,11 +157,9 @@
if (ioctl(fd, DIOCGDINFO, &lab) == -1) {
seterror(errno);
- (void)close(fd);
rv = -1;
goto out;
}
- close(fd);
parta = &lab.d_partitions[DISKPART(sb.st_rdev)];
size = (uint64_t)lab.d_secsize * parta->p_size;
@@ -175,6 +171,8 @@
*sizep = size;
if (rv == 0 && ftp)
*ftp = ft;
+ if (fd != -1)
+ close(fd);
return rv;
}
Home |
Main Index |
Thread Index |
Old Index