소스 검색

Fix several minor memleaks.

Adam Heath 24 년 전
부모
커밋
84d898ec49
10개의 변경된 파일22개의 추가작업 그리고 5개의 파일을 삭제
  1. 6 0
      ChangeLog
  2. 1 0
      debian/changelog
  3. 3 0
      lib/dbmodify.c
  4. 1 0
      lib/dump.c
  5. 2 4
      lib/lock.c
  6. 1 0
      lib/startup.c
  7. 1 0
      lib/tarfn.c
  8. 2 1
      main/configure.c
  9. 1 0
      main/filesdb.c
  10. 4 0
      main/query.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+Thu Aug 29 14:51:35 CDT 2002 Adam Heath <doogie@debian.org>
+
+  * 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 <doogie@debian.org>
 
   * lib/parsehelp.c: Fix corruption of available file, caused by use of

+ 1 - 0
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 <doogie@debian.org>  UNRELEASED
 

+ 3 - 0
lib/dbmodify.c

@@ -218,6 +218,9 @@ void modstatdb_shutdown(void) {
     break;
   }
 
+  free(statusfile);
+  free(availablefile);
+  free(importanttmpfile);
   free(updatefnbuf);
 }
 

+ 1 - 0
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))

+ 2 - 4
lib/lock.c

@@ -32,12 +32,10 @@
 #include <dpkg.h>
 #include <dpkg-db.h>
 
-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);
 }

+ 1 - 0
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();
 }

+ 1 - 0
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;

+ 2 - 1
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,&currenthash,cdr.buf);

+ 1 - 0
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--;
 }

+ 4 - 0
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) {