Linux Device Mapper development
 help / color / mirror / Atom feed
From: neilb@suse.de
To: dm-devel@redhat.com
Subject: [dmraid 2/4] Avoid fd leak in remove_device_partitions.
Date: Thu, 17 Dec 2009 16:44:12 +1100	[thread overview]
Message-ID: <20091217054520.996066834@suse.de> (raw)
In-Reply-To: 20091217054410.410634166@suse.de

[-- Attachment #1: dmraid-fdleak.patch --]
[-- Type: text/plain, Size: 878 bytes --]

As this removes partitions for a list of devices, it could leak
a large number of file descriptors.

Reported-by:  David Binderman <dcb314@hotmail.com>
From: crrodriguez@opensuse.org
Signed-off-by: NeilBrown <neilb@suse.de>

---
 lib/device/partition.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- dmraid-16.orig/lib/device/partition.c
+++ dmraid-16/lib/device/partition.c
@@ -30,12 +30,15 @@ _remove_subset_partitions(struct lib_con
 		/* 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))
+					(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;
 }

  parent reply	other threads:[~2009-12-17  5:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-17  5:44 [dmraid 0/4] A few patches for dmraid neilb
2009-12-17  5:44 ` [dmraid 1/4] Parse "-cc" as required by man page neilb
2009-12-17 16:50   ` Heinz Mauelshagen
2009-12-17  5:44 ` neilb [this message]
2009-12-17  5:44 ` [dmraid 3/4] Fix min/max macros neilb
2009-12-17  5:44 ` [dmraid 4/4] Fix two issues with installing shared libraries neilb

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=20091217054520.996066834@suse.de \
    --to=neilb@suse.de \
    --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