Linux Device Mapper development
 help / color / mirror / Atom feed
From: heinzm@sourceware.org
To: dm-cvs@sourceware.org, dm-devel@redhat.com
Subject: dmraid/lib/device partition.c
Date: 17 Dec 2009 14:29:24 -0000	[thread overview]
Message-ID: <20091217142924.27772.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/dm
Module name:	dmraid
Changes by:	heinzm@sourceware.org	2009-12-17 14:29:24

Modified files:
	lib/device     : partition.c 

Log message:
	Avoid fd leak in _remove_subset_partitions (Neil Brown)

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/dmraid/lib/device/partition.c.diff?cvsroot=dm&r1=1.1&r2=1.2

--- dmraid/lib/device/partition.c	2009/12/16 11:39:18	1.1
+++ dmraid/lib/device/partition.c	2009/12/17 14:29:24	1.2
@@ -23,20 +23,27 @@
 
 	list_for_each_entry(rd, &rs->devs, devs) {
 		int fd = open(rd->di->path, O_RDWR);
+
 		if (fd < 0)
 			LOG_ERR(lc, 0, "opening %s: %s\n", rd->di->path,
 				strerror(errno));
 
 		/* There is no way to enumerate partitions */
 		for (part.pno = 1; part.pno <= 256; part.pno++) {
-			if (ioctl(fd, BLKPG, &io) < 0 && errno != ENXIO &&
-					(part.pno < 16 || errno != EINVAL))
+			if (ioctl(fd, BLKPG, &io) < 0 &&
+			    errno != ENXIO &&
+			    (part.pno < 16 || errno != EINVAL)) {
+				close(fd);
 				LOG_ERR(lc, 0,
 					"removing part %d from %s: %s\n",
 					part.pno, rd->di->path,
 					strerror(errno));
+			}
 		}
+
+		close(fd);
 	}
+
 	return 1;
 }
 

                 reply	other threads:[~2009-12-17 14:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091217142924.27772.qmail@sourceware.org \
    --to=heinzm@sourceware.org \
    --cc=dm-cvs@sourceware.org \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox