From: Adam Heath Date: Thu, 29 Aug 2002 19:58:11 +0000 (+0000) Subject: Fix several minor memleaks. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84d898ec491df14f875e097e18742b62f791d3aa;p=dpkg Fix several minor memleaks. --- diff --git a/ChangeLog b/ChangeLog index 3249eeee..914d0fad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Aug 29 14:51:35 CDT 2002 Adam Heath + + * lib/dbmodify.c, lib/dump.c, lib/lock.c, lib/startup.c, lib/tarfn.c + main/configure.c, main/filesdb.c, main/query.c: Fix several minor + memleaks. + Thu Aug 29 14:42:05 CDT 2002 Adam Heath * lib/parsehelp.c: Fix corruption of available file, caused by use of diff --git a/debian/changelog b/debian/changelog index d7f44cfb..4393c972 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,7 @@ dpkg (1.10.5) unstable; urgency=low stanza, and process them all. Closes: #147492. * Fix corruption of available file, caused by use of memory that was previously freed. Closes: #154257. + * Fix several minor memleaks. -- Adam Heath UNRELEASED diff --git a/lib/dbmodify.c b/lib/dbmodify.c index 1e73583f..2b69d3fd 100644 --- a/lib/dbmodify.c +++ b/lib/dbmodify.c @@ -218,6 +218,9 @@ void modstatdb_shutdown(void) { break; } + free(statusfile); + free(availablefile); + free(importanttmpfile); free(updatefnbuf); } diff --git a/lib/dump.c b/lib/dump.c index 9446ce5b..13483c19 100644 --- a/lib/dump.c +++ b/lib/dump.c @@ -304,6 +304,7 @@ void writedb(const char *filename, int available, int mustsync) { which, pigp->name, filename); varbufreset(&vb); } + iterpkgend(it); varbuffree(&vb); if (mustsync) { if (fflush(file)) diff --git a/lib/lock.c b/lib/lock.c index 6294216d..1787b1dd 100644 --- a/lib/lock.c +++ b/lib/lock.c @@ -32,12 +32,10 @@ #include #include -static char *dblockfile= NULL; static int dblockfd= -1; static void cu_unlockdb(int argc, void **argv) { struct flock fl; - assert(dblockfile); assert(dblockfd >= 0); fl.l_type= F_UNLCK; fl.l_whence= SEEK_SET; @@ -54,13 +52,12 @@ void unlockdatabase(const char *admindir) { void lockdatabase(const char *admindir) { int n; struct flock fl; + char *dblockfile= NULL; - if (!dblockfile) { n= strlen(admindir); dblockfile= m_malloc(n+sizeof(LOCKFILE)+2); strcpy(dblockfile,admindir); strcpy(dblockfile+n, "/" LOCKFILE); - } if (dblockfd == -1) { dblockfd= open(dblockfile, O_RDWR|O_CREAT|O_TRUNC, 0660); if (dblockfd == -1) { @@ -79,5 +76,6 @@ void lockdatabase(const char *admindir) { ohshite(_("unable to lock dpkg status database")); } setcloexec(dblockfd, dblockfile); + free(dblockfile); push_cleanup(cu_unlockdb,~0, NULL,0, 0); } diff --git a/lib/startup.c b/lib/startup.c index 32c835de..a669af54 100644 --- a/lib/startup.c +++ b/lib/startup.c @@ -60,4 +60,5 @@ void standard_startup(jmp_buf *ejbuf, int argc, const char *const **argv, const void standard_shutdown(void) { set_error_display(0,0); error_unwind(ehflag_normaltidy); + nffreeall(); } diff --git a/lib/tarfn.c b/lib/tarfn.c index 6752f2b5..803b1f0f 100644 --- a/lib/tarfn.c +++ b/lib/tarfn.c @@ -266,6 +266,7 @@ TarExtractor( free(symListPointer); symListPointer = symListBottom; } + free(symListPointer); if ( status > 0 ) { /* Read partial header record */ errno = 0; /* Indicates broken tarfile */ return -1; diff --git a/main/configure.c b/main/configure.c index 970a8930..b82a6931 100644 --- a/main/configure.c +++ b/main/configure.c @@ -81,6 +81,7 @@ void deferred_configure(struct pkginfo *pkg) { char *currenthash= 0, *newdisthash= 0; struct stat stab; enum conffopt what; + static const char *EMPTY_HASH = "-"; if (pkg->status == stat_notinstalled) ohshit(_("no package named `%s' is installed, cannot configure"),pkg->name); @@ -157,7 +158,7 @@ void deferred_configure(struct pkginfo *pkg) { for (conff= pkg->installed.conffiles; conff; conff= conff->next) { r= conffderef(pkg, &cdr, conff->name); if (r == -1) { - conff->hash= nfstrsave("-"); + conff->hash= EMPTY_HASH; continue; } md5hash(pkg,¤thash,cdr.buf); diff --git a/main/filesdb.c b/main/filesdb.c index bac9cbc3..e642c01e 100644 --- a/main/filesdb.c +++ b/main/filesdb.c @@ -511,6 +511,7 @@ void ensure_diversions(void) { diversions= oicontest; } if (ferror(file)) ohshite(_("read error in diversions [i]")); + fclose(file); onerr_abort--; } diff --git a/main/query.c b/main/query.c index 9b8c69cb..2ff4a57d 100644 --- a/main/query.c +++ b/main/query.c @@ -204,6 +204,7 @@ void listpackages(const char *const *argv) { } if (ferror(stdout)) werr("stdout"); if (ferror(stderr)) werr("stderr"); + modstatdb_shutdown(); } static int searchoutput(struct filenamenode *namenode) { @@ -282,6 +283,7 @@ void searchfiles(const char *const *argv) { if (ferror(stdout)) werr("stdout"); } } + modstatdb_shutdown(); } void enqperpackage(const char *const *argv) { @@ -372,6 +374,7 @@ void enqperpackage(const char *const *argv) { "and dpkg --contents (= dpkg-deb --contents) to list their contents.\n"),stderr); if (ferror(stdout)) werr("stdout"); } + modstatdb_shutdown(); } void showpackages(const char *const *argv) { @@ -424,6 +427,7 @@ void showpackages(const char *const *argv) { if (ferror(stdout)) werr("stdout"); if (ferror(stderr)) werr("stderr"); freeformat(fmt); + modstatdb_shutdown(); } static void printversion(void) {