Просмотр исходного кода

* make sure that the pkgRecords D'tor does not segfault

Michael Vogt лет назад: 21
Родитель
Сommit
14cd494a9f
3 измененных файлов с 6 добавлено и 2 удалено
  1. 4 1
      apt-pkg/pkgrecords.cc
  2. 1 0
      apt-pkg/pkgrecords.h
  3. 1 1
      cmdline/apt-get.cc

+ 4 - 1
apt-pkg/pkgrecords.cc

@@ -42,6 +42,9 @@ pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(0)
       if (Files[I->ID] == 0)
 	 return;
    }   
+   // We store that to make sure that the destructor won't segfault,
+   // even if the Cache object was destructed before this instance.
+   PackageFileCount = Cache.HeaderP->PackageFileCount;
 }
 									/*}}}*/
 // Records::~pkgRecords - Destructor					/*{{{*/
@@ -49,7 +52,7 @@ pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(0)
 /* */
 pkgRecords::~pkgRecords()
 {
-   for (unsigned I = 0; I != Cache.HeaderP->PackageFileCount; I++)
+   for (unsigned I = 0; I != PackageFileCount; I++)
       delete Files[I];
    delete [] Files;
 }

+ 1 - 0
apt-pkg/pkgrecords.h

@@ -33,6 +33,7 @@ class pkgRecords
    
    pkgCache &Cache;
    Parser **Files;
+   int PackageFileCount;
       
    public:
 

+ 1 - 1
cmdline/apt-get.cc

@@ -2013,7 +2013,7 @@ bool DoSource(CommandLine &CmdL)
 	    if (system(S) != 0)
 	    {
 	       fprintf(stderr,_("Unpack command '%s' failed.\n"),S);
-	       fprintf(stderr,_("Check if the 'dpkg-dev' package is installed.\n");
+	       fprintf(stderr,_("Check if the 'dpkg-dev' package is installed.\n"));
 	       _exit(1);
 	    }	    
 	 }