[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Resource leak and possible double-fclose



Hi,

I found a leak and a possible double-fclosing in some parts of dpkg when 
checking it with cppcheck. Attached are patches fixing the bugs.

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net
From ade42f031ea68af1fd4278cf343870cbc3d1f2ea Mon Sep 17 00:00:00 2001
From: Raphael Geissert <atomo64@gmail.com>
Date: Mon, 15 Feb 2010 01:08:14 -0600
Subject: [PATCH 1/2] Fix resource leak in dpkg-deb

---
 dpkg-deb/info.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/dpkg-deb/info.c b/dpkg-deb/info.c
index 9ce7e76..ca9c747 100644
--- a/dpkg-deb/info.c
+++ b/dpkg-deb/info.c
@@ -185,6 +185,8 @@ static void info_list(const char *debar, const char *directory) {
       putc('\n', stdout);
   }
 
+  fclose(cc);
+
   m_output(stdout, _("<standard output>"));
 }
 
-- 
1.6.6.1

From 3afa3351bebb3d379a85ffedcf200fd6723df3dc Mon Sep 17 00:00:00 2001
From: Raphael Geissert <atomo64@gmail.com>
Date: Mon, 15 Feb 2010 01:10:21 -0600
Subject: [PATCH 2/2] Fix a possible resource double-deallocation

---
 dselect/methparse.cc |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/dselect/methparse.cc b/dselect/methparse.cc
index ba03903..2b3edd3 100644
--- a/dselect/methparse.cc
+++ b/dselect/methparse.cc
@@ -290,8 +290,7 @@ void writecurrentopt() {
   if (fprintf(cmo,"%s %s\n",coption->meth->name,coption->name) == EOF) {
     fclose(cmo);
     ohshite(_("unable to write new option to `%.250s'"),newfile);
-  }
-  if (fclose(cmo))
+  } else if (fclose(cmo))
     ohshite(_("unable to close new option file `%.250s'"),newfile);
   if (rename(newfile,methoptfile))
     ohshite(_("unable to install new option as `%.250s'"),methoptfile);
-- 
1.6.6.1


Reply to: