]> git.saurik.com Git - apt.git/commitdiff
fix memory leaks reported by -fsanitize
authorDavid Kalnischkies <david@kalnischkies.de>
Thu, 18 Jun 2015 15:33:15 +0000 (17:33 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Mon, 10 Aug 2015 15:25:25 +0000 (17:25 +0200)
Various small leaks here and there. Nothing particularily big, but still
good to fix. Found by the sanitizers while running our testcases.

Reported-By: gcc -fsanitize
Git-Dch: Ignore

26 files changed:
apt-pkg/acquire-item.cc
apt-pkg/acquire-item.h
apt-pkg/acquire-worker.cc
apt-pkg/cachefile.cc
apt-pkg/contrib/cdromutl.cc
apt-pkg/contrib/gpgv.cc
apt-pkg/deb/debmetaindex.cc
apt-pkg/deb/debrecords.cc
apt-pkg/deb/dpkgpm.cc
apt-pkg/indexrecords.cc
apt-pkg/tagfile.cc
apt-pkg/tagfile.h
apt-private/private-cacheset.h
apt-private/private-output.cc
buildlib/environment.mak.in
cmdline/apt-cache.cc
cmdline/apt-get.cc
ftparchive/apt-ftparchive.cc
ftparchive/cachedb.cc
ftparchive/writer.cc
ftparchive/writer.h
test/integration/framework
test/libapt/cdrom_test.cc
test/libapt/file-helpers.cc
test/libapt/file-helpers.h
test/libapt/sourcelist_test.cc

index 222ca8931b82699fdac9253adda862c3fcbbf847..0ab52a0cdfcc559260f2eabdc4757384a2eb9e25 100644 (file)
@@ -109,7 +109,7 @@ static std::string GetDiffsPatchFileName(std::string const &Final)  /*{{{*/
 }
                                                                        /*}}}*/
 
 }
                                                                        /*}}}*/
 
-static bool AllowInsecureRepositories(indexRecords const * const MetaIndexParser, pkgAcqMetaBase * const TransactionManager, pkgAcquire::Item * const I) /*{{{*/
+static bool AllowInsecureRepositories(indexRecords const * const MetaIndexParser, pkgAcqMetaClearSig * const TransactionManager, pkgAcquire::Item * const I) /*{{{*/
 {
    if(MetaIndexParser->IsAlwaysTrusted() || _config->FindB("Acquire::AllowInsecureRepositories") == true)
       return true;
 {
    if(MetaIndexParser->IsAlwaysTrusted() || _config->FindB("Acquire::AllowInsecureRepositories") == true)
       return true;
@@ -661,7 +661,7 @@ std::string pkgAcquire::Item::HashSum() const                               /*{{{*/
                                                                        /*}}}*/
 
 pkgAcqTransactionItem::pkgAcqTransactionItem(pkgAcquire * const Owner, /*{{{*/
                                                                        /*}}}*/
 
 pkgAcqTransactionItem::pkgAcqTransactionItem(pkgAcquire * const Owner, /*{{{*/
-      pkgAcqMetaBase * const transactionManager, IndexTarget const &target) :
+      pkgAcqMetaClearSig * const transactionManager, IndexTarget const &target) :
    pkgAcquire::Item(Owner), d(NULL), Target(target), TransactionManager(transactionManager)
 {
    if (TransactionManager != this)
    pkgAcquire::Item(Owner), d(NULL), Target(target), TransactionManager(transactionManager)
 {
    if (TransactionManager != this)
@@ -680,12 +680,11 @@ HashStringList pkgAcqTransactionItem::GetExpectedHashesFor(std::string const &Me
 
 // AcqMetaBase - Constructor                                           /*{{{*/
 pkgAcqMetaBase::pkgAcqMetaBase(pkgAcquire * const Owner,
 
 // AcqMetaBase - Constructor                                           /*{{{*/
 pkgAcqMetaBase::pkgAcqMetaBase(pkgAcquire * const Owner,
-      pkgAcqMetaBase * const TransactionManager,
+      pkgAcqMetaClearSig * const TransactionManager,
       std::vector<IndexTarget> const &IndexTargets,
       std::vector<IndexTarget> const &IndexTargets,
-      IndexTarget const &DataTarget,
-      indexRecords * const MetaIndexParser)
+      IndexTarget const &DataTarget)
 : pkgAcqTransactionItem(Owner, TransactionManager, DataTarget), d(NULL),
 : pkgAcqTransactionItem(Owner, TransactionManager, DataTarget), d(NULL),
-   MetaIndexParser(MetaIndexParser), LastMetaIndexParser(NULL), IndexTargets(IndexTargets),
+   IndexTargets(IndexTargets),
    AuthPass(false), IMSHit(false)
 {
 }
    AuthPass(false), IMSHit(false)
 {
 }
@@ -1047,7 +1046,7 @@ bool pkgAcqMetaBase::VerifyVendor(string const &Message)          /*{{{*/
         std::string errmsg;
         strprintf(errmsg,
               // TRANSLATOR: The first %s is the URL of the bad Release file, the second is
         std::string errmsg;
         strprintf(errmsg,
               // TRANSLATOR: The first %s is the URL of the bad Release file, the second is
-              // the time since then the file is invalid - formated in the same way as in
+              // the time since then the file is invalid - formatted in the same way as in
               // the download progress display (e.g. 7d 3h 42min 1s)
               _("Release file for %s is expired (invalid since %s). "
                  "Updates for this repository will not be applied."),
               // the download progress display (e.g. 7d 3h 42min 1s)
               _("Release file for %s is expired (invalid since %s). "
                  "Updates for this repository will not be applied."),
@@ -1098,16 +1097,19 @@ bool pkgAcqMetaBase::VerifyVendor(string const &Message)                /*{{{*/
    return true;
 }
                                                                        /*}}}*/
    return true;
 }
                                                                        /*}}}*/
-pkgAcqMetaBase::~pkgAcqMetaBase() {}
+pkgAcqMetaBase::~pkgAcqMetaBase()
+{
+}
 
 pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire * const Owner,       /*{{{*/
       IndexTarget const &ClearsignedTarget,
       IndexTarget const &DetachedDataTarget, IndexTarget const &DetachedSigTarget,
       std::vector<IndexTarget> const &IndexTargets,
       indexRecords * const MetaIndexParser) :
 
 pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire * const Owner,       /*{{{*/
       IndexTarget const &ClearsignedTarget,
       IndexTarget const &DetachedDataTarget, IndexTarget const &DetachedSigTarget,
       std::vector<IndexTarget> const &IndexTargets,
       indexRecords * const MetaIndexParser) :
-   pkgAcqMetaIndex(Owner, this, ClearsignedTarget, DetachedSigTarget, IndexTargets, MetaIndexParser),
+   pkgAcqMetaIndex(Owner, this, ClearsignedTarget, DetachedSigTarget, IndexTargets),
    d(NULL), ClearsignedTarget(ClearsignedTarget),
    d(NULL), ClearsignedTarget(ClearsignedTarget),
-   DetachedDataTarget(DetachedDataTarget)
+   DetachedDataTarget(DetachedDataTarget),
+   MetaIndexParser(MetaIndexParser), LastMetaIndexParser(NULL)
 {
    // index targets + (worst case:) Release/Release.gpg
    ExpectedAdditionalItems = IndexTargets.size() + 2;
 {
    // index targets + (worst case:) Release/Release.gpg
    ExpectedAdditionalItems = IndexTargets.size() + 2;
@@ -1116,6 +1118,10 @@ pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire * const Owner, /*{{{*/
                                                                        /*}}}*/
 pkgAcqMetaClearSig::~pkgAcqMetaClearSig()                              /*{{{*/
 {
                                                                        /*}}}*/
 pkgAcqMetaClearSig::~pkgAcqMetaClearSig()                              /*{{{*/
 {
+   if (MetaIndexParser != NULL)
+      delete MetaIndexParser;
+   if (LastMetaIndexParser != NULL)
+      delete LastMetaIndexParser;
 }
                                                                        /*}}}*/
 // pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers        /*{{{*/
 }
                                                                        /*}}}*/
 // pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers        /*{{{*/
@@ -1180,7 +1186,7 @@ void pkgAcqMetaClearSig::Failed(string const &Message,pkgAcquire::MethodConfig c
       TransactionManager->TransactionStageRemoval(this, GetFinalFilename());
       Status = StatDone;
 
       TransactionManager->TransactionStageRemoval(this, GetFinalFilename());
       Status = StatDone;
 
-      new pkgAcqMetaIndex(Owner, TransactionManager, DetachedDataTarget, DetachedSigTarget, IndexTargets, TransactionManager->MetaIndexParser);
+      new pkgAcqMetaIndex(Owner, TransactionManager, DetachedDataTarget, DetachedSigTarget, IndexTargets);
    }
    else
    {
    }
    else
    {
@@ -1240,12 +1246,11 @@ void pkgAcqMetaClearSig::Failed(string const &Message,pkgAcquire::MethodConfig c
                                                                        /*}}}*/
 
 pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire * const Owner,             /*{{{*/
                                                                        /*}}}*/
 
 pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire * const Owner,             /*{{{*/
-                                 pkgAcqMetaBase * const TransactionManager,
+                                 pkgAcqMetaClearSig * const TransactionManager,
                                 IndexTarget const &DataTarget,
                                 IndexTarget const &DetachedSigTarget,
                                 IndexTarget const &DataTarget,
                                 IndexTarget const &DetachedSigTarget,
-                                vector<IndexTarget> const &IndexTargets,
-                                indexRecords * const MetaIndexParser) :
-   pkgAcqMetaBase(Owner, TransactionManager, IndexTargets, DataTarget, MetaIndexParser), d(NULL),
+                                vector<IndexTarget> const &IndexTargets) :
+   pkgAcqMetaBase(Owner, TransactionManager, IndexTargets, DataTarget), d(NULL),
    DetachedSigTarget(DetachedSigTarget)
 {
    if(_config->FindB("Debug::Acquire::Transaction", false) == true)
    DetachedSigTarget(DetachedSigTarget)
 {
    if(_config->FindB("Debug::Acquire::Transaction", false) == true)
@@ -1324,7 +1329,7 @@ pkgAcqMetaIndex::~pkgAcqMetaIndex() {}
 
 // AcqMetaSig::AcqMetaSig - Constructor                                        /*{{{*/
 pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire * const Owner,
 
 // AcqMetaSig::AcqMetaSig - Constructor                                        /*{{{*/
 pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire * const Owner,
-      pkgAcqMetaBase * const TransactionManager,
+      pkgAcqMetaClearSig * const TransactionManager,
       IndexTarget const &Target,
       pkgAcqMetaIndex * const MetaIndex) :
    pkgAcqTransactionItem(Owner, TransactionManager, Target), d(NULL), MetaIndex(MetaIndex)
       IndexTarget const &Target,
       pkgAcqMetaIndex * const MetaIndex) :
    pkgAcqTransactionItem(Owner, TransactionManager, Target), d(NULL), MetaIndex(MetaIndex)
@@ -1487,7 +1492,7 @@ void pkgAcqMetaSig::Failed(string const &Message,pkgAcquire::MethodConfig const
 
 // AcqBaseIndex - Constructor                                          /*{{{*/
 pkgAcqBaseIndex::pkgAcqBaseIndex(pkgAcquire * const Owner,
 
 // AcqBaseIndex - Constructor                                          /*{{{*/
 pkgAcqBaseIndex::pkgAcqBaseIndex(pkgAcquire * const Owner,
-      pkgAcqMetaBase * const TransactionManager,
+      pkgAcqMetaClearSig * const TransactionManager,
       IndexTarget const &Target)
 : pkgAcqTransactionItem(Owner, TransactionManager, Target), d(NULL)
 {
       IndexTarget const &Target)
 : pkgAcqTransactionItem(Owner, TransactionManager, Target), d(NULL)
 {
@@ -1503,9 +1508,9 @@ pkgAcqBaseIndex::~pkgAcqBaseIndex() {}
  * the original packages file
  */
 pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire * const Owner,
  * the original packages file
  */
 pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire * const Owner,
-                                 pkgAcqMetaBase * const TransactionManager,
+                                 pkgAcqMetaClearSig * const TransactionManager,
                                  IndexTarget const &Target)
                                  IndexTarget const &Target)
-   : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL)
+   : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL), diffs(NULL)
 {
    Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
 
 {
    Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
 
@@ -1840,7 +1845,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
       new pkgAcqIndexDiffs(Owner, TransactionManager, Target, available_patches);
    else
    {
       new pkgAcqIndexDiffs(Owner, TransactionManager, Target, available_patches);
    else
    {
-      std::vector<pkgAcqIndexMergeDiffs*> *diffs = new std::vector<pkgAcqIndexMergeDiffs*>(available_patches.size());
+      diffs = new std::vector<pkgAcqIndexMergeDiffs*>(available_patches.size());
       for(size_t i = 0; i < available_patches.size(); ++i)
         (*diffs)[i] = new pkgAcqIndexMergeDiffs(Owner, TransactionManager,
                Target,
       for(size_t i = 0; i < available_patches.size(); ++i)
         (*diffs)[i] = new pkgAcqIndexMergeDiffs(Owner, TransactionManager,
                Target,
@@ -1896,7 +1901,11 @@ void pkgAcqDiffIndex::Done(string const &Message,HashStringList const &Hashes,   /
    return;
 }
                                                                        /*}}}*/
    return;
 }
                                                                        /*}}}*/
-pkgAcqDiffIndex::~pkgAcqDiffIndex() {}
+pkgAcqDiffIndex::~pkgAcqDiffIndex()
+{
+   if (diffs != NULL)
+      delete diffs;
+}
 
 // AcqIndexDiffs::AcqIndexDiffs - Constructor                          /*{{{*/
 // ---------------------------------------------------------------------
 
 // AcqIndexDiffs::AcqIndexDiffs - Constructor                          /*{{{*/
 // ---------------------------------------------------------------------
@@ -1904,7 +1913,7 @@ pkgAcqDiffIndex::~pkgAcqDiffIndex() {}
  * for each diff and the index
  */
 pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire * const Owner,
  * for each diff and the index
  */
 pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire * const Owner,
-                                   pkgAcqMetaBase * const TransactionManager,
+                                   pkgAcqMetaClearSig * const TransactionManager,
                                    IndexTarget const &Target,
                                   vector<DiffInfo> const &diffs)
    : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL),
                                    IndexTarget const &Target,
                                   vector<DiffInfo> const &diffs)
    : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL),
@@ -2127,7 +2136,7 @@ pkgAcqIndexDiffs::~pkgAcqIndexDiffs() {}
 
 // AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor                        /*{{{*/
 pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire * const Owner,
 
 // AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor                        /*{{{*/
 pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire * const Owner,
-                                             pkgAcqMetaBase * const TransactionManager,
+                                             pkgAcqMetaClearSig * const TransactionManager,
                                              IndexTarget const &Target,
                                              DiffInfo const &patch,
                                              std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches)
                                              IndexTarget const &Target,
                                              DiffInfo const &patch,
                                              std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches)
@@ -2272,7 +2281,7 @@ pkgAcqIndexMergeDiffs::~pkgAcqIndexMergeDiffs() {}
 
 // AcqIndex::AcqIndex - Constructor                                    /*{{{*/
 pkgAcqIndex::pkgAcqIndex(pkgAcquire * const Owner,
 
 // AcqIndex::AcqIndex - Constructor                                    /*{{{*/
 pkgAcqIndex::pkgAcqIndex(pkgAcquire * const Owner,
-                         pkgAcqMetaBase * const TransactionManager,
+                         pkgAcqMetaClearSig * const TransactionManager,
                          IndexTarget const &Target)
    : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL), Stage(STAGE_DOWNLOAD)
 {
                          IndexTarget const &Target)
    : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL), Stage(STAGE_DOWNLOAD)
 {
index c4bbfc7a1542b3568240118ddb6463c1b453d7fe..4d235dce2a5f36870d7fe70ee76afbf2a11b7eb1 100644 (file)
@@ -46,7 +46,8 @@
 class indexRecords;
 class pkgRecords;
 class pkgSourceList;
 class indexRecords;
 class pkgRecords;
 class pkgSourceList;
-class pkgAcqMetaBase;
+class pkgAcqMetaClearSig;
+class pkgAcqIndexMergeDiffs;
 
 class pkgAcquire::Item : public WeakPointable                          /*{{{*/
 /** \brief Represents the process by which a pkgAcquire object should
 
 class pkgAcquire::Item : public WeakPointable                          /*{{{*/
 /** \brief Represents the process by which a pkgAcquire object should
@@ -339,6 +340,7 @@ class pkgAcquire::Item : public WeakPointable                               /*{{{*/
    void * const d;
 
    friend class pkgAcqMetaBase;
    void * const d;
 
    friend class pkgAcqMetaBase;
+   friend class pkgAcqMetaClearSig;
 };
                                                                        /*}}}*/
 class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item                /*{{{*/
 };
                                                                        /*}}}*/
 class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item                /*{{{*/
@@ -356,7 +358,7 @@ class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item             /*{{{*/
    std::string PartialFile;
 
    /** \brief TransactionManager */
    std::string PartialFile;
 
    /** \brief TransactionManager */
-   pkgAcqMetaBase * const TransactionManager;
+   pkgAcqMetaClearSig * const TransactionManager;
 
    enum TransactionStates {
       TransactionCommit,
 
    enum TransactionStates {
       TransactionCommit,
@@ -370,10 +372,11 @@ class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item           /*{{{*/
    virtual bool HashesRequired() const;
 
 
    virtual bool HashesRequired() const;
 
 
-   pkgAcqTransactionItem(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager, IndexTarget const &Target);
+   pkgAcqTransactionItem(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager, IndexTarget const &Target);
    virtual ~pkgAcqTransactionItem();
 
    friend class pkgAcqMetaBase;
    virtual ~pkgAcqTransactionItem();
 
    friend class pkgAcqMetaBase;
+   friend class pkgAcqMetaClearSig;
 };
                                                                        /*}}}*/
 class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem         /*{{{*/
 };
                                                                        /*}}}*/
 class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem         /*{{{*/
@@ -383,12 +386,6 @@ class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem             /*{{{*/
  protected:
    std::vector<pkgAcqTransactionItem*> Transaction;
 
  protected:
    std::vector<pkgAcqTransactionItem*> Transaction;
 
- public:
-   /** \brief A package-system-specific parser for the meta-index file. */
-   indexRecords *MetaIndexParser;
-   indexRecords *LastMetaIndexParser;
- protected:
-
    /** \brief The index files which should be looked up in the meta-index
     *  and then downloaded.
     */
    /** \brief The index files which should be looked up in the meta-index
     *  and then downloaded.
     */
@@ -473,10 +470,9 @@ class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem             /*{{{*/
    /** \brief Get the full pathname of the final file for the current URI */
    virtual std::string GetFinalFilename() const;
 
    /** \brief Get the full pathname of the final file for the current URI */
    virtual std::string GetFinalFilename() const;
 
-   pkgAcqMetaBase(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+   pkgAcqMetaBase(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
                  std::vector<IndexTarget> const &IndexTargets,
                  std::vector<IndexTarget> const &IndexTargets,
-                 IndexTarget const &DataTarget,
-                 indexRecords* const MetaIndexParser);
+                 IndexTarget const &DataTarget);
    virtual ~pkgAcqMetaBase();
 };
                                                                        /*}}}*/
    virtual ~pkgAcqMetaBase();
 };
                                                                        /*}}}*/
@@ -509,9 +505,9 @@ class APT_HIDDEN pkgAcqMetaIndex : public pkgAcqMetaBase
    virtual void Finished();
 
    /** \brief Create a new pkgAcqMetaIndex. */
    virtual void Finished();
 
    /** \brief Create a new pkgAcqMetaIndex. */
-   pkgAcqMetaIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+   pkgAcqMetaIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
                   IndexTarget const &DataTarget, IndexTarget const &DetachedSigTarget,
                   IndexTarget const &DataTarget, IndexTarget const &DetachedSigTarget,
-                  std::vector<IndexTarget> const &IndexTargets, indexRecords * const MetaIndexParser);
+                  std::vector<IndexTarget> const &IndexTargets);
    virtual ~pkgAcqMetaIndex();
 
    friend class pkgAcqMetaSig;
    virtual ~pkgAcqMetaIndex();
 
    friend class pkgAcqMetaSig;
@@ -548,8 +544,8 @@ class APT_HIDDEN pkgAcqMetaSig : public pkgAcqTransactionItem
                     pkgAcquire::MethodConfig const * const Cnf);
 
    /** \brief Create a new pkgAcqMetaSig. */
                     pkgAcquire::MethodConfig const * const Cnf);
 
    /** \brief Create a new pkgAcqMetaSig. */
-   pkgAcqMetaSig(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager, IndexTarget const &Target,
-        pkgAcqMetaIndex * const MetaIndex);
+   pkgAcqMetaSig(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
+        IndexTarget const &Target, pkgAcqMetaIndex * const MetaIndex);
    virtual ~pkgAcqMetaSig();
 };
                                                                        /*}}}*/
    virtual ~pkgAcqMetaSig();
 };
                                                                        /*}}}*/
@@ -561,7 +557,11 @@ class APT_HIDDEN pkgAcqMetaClearSig : public pkgAcqMetaIndex
    IndexTarget const ClearsignedTarget;
    IndexTarget const DetachedDataTarget;
 
    IndexTarget const ClearsignedTarget;
    IndexTarget const DetachedDataTarget;
 
-public:
+ public:
+   /** \brief A package-system-specific parser for the meta-index file. */
+   indexRecords *MetaIndexParser;
+   indexRecords *LastMetaIndexParser;
+
    virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
    virtual std::string Custom600Headers() const;
    virtual void Done(std::string const &Message, HashStringList const &Hashes,
    virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
    virtual std::string Custom600Headers() const;
    virtual void Done(std::string const &Message, HashStringList const &Hashes,
@@ -586,7 +586,7 @@ class APT_HIDDEN pkgAcqBaseIndex : public pkgAcqTransactionItem
    /** \brief Get the full pathname of the final file for the current URI */
    virtual std::string GetFinalFilename() const;
 
    /** \brief Get the full pathname of the final file for the current URI */
    virtual std::string GetFinalFilename() const;
 
-   pkgAcqBaseIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+   pkgAcqBaseIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
                    IndexTarget const &Target);
    virtual ~pkgAcqBaseIndex();
 };
                    IndexTarget const &Target);
    virtual ~pkgAcqBaseIndex();
 };
@@ -603,6 +603,7 @@ class APT_HIDDEN pkgAcqBaseIndex : public pkgAcqTransactionItem
 class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
 {
    void * const d;
 class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
 {
    void * const d;
+   std::vector<pkgAcqIndexMergeDiffs*> * diffs;
 
  protected:
    /** \brief If \b true, debugging information will be written to std::clog. */
 
  protected:
    /** \brief If \b true, debugging information will be written to std::clog. */
@@ -650,7 +651,7 @@ class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
     *
     *  \param ShortDesc A short description of the list file to download.
     */
     *
     *  \param ShortDesc A short description of the list file to download.
     */
-   pkgAcqDiffIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+   pkgAcqDiffIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
                    IndexTarget const &Target);
    virtual ~pkgAcqDiffIndex();
  private:
                    IndexTarget const &Target);
    virtual ~pkgAcqDiffIndex();
  private:
@@ -749,7 +750,7 @@ class APT_HIDDEN pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
     *  \param allPatches contains all related items so that each item can
     *  check if it was the last one to complete the download step
     */
     *  \param allPatches contains all related items so that each item can
     *  check if it was the last one to complete the download step
     */
-   pkgAcqIndexMergeDiffs(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+   pkgAcqIndexMergeDiffs(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
                          IndexTarget const &Target, DiffInfo const &patch,
                          std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
    virtual ~pkgAcqIndexMergeDiffs();
                          IndexTarget const &Target, DiffInfo const &patch,
                          std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
    virtual ~pkgAcqIndexMergeDiffs();
@@ -863,7 +864,7 @@ class APT_HIDDEN pkgAcqIndexDiffs : public pkgAcqBaseIndex
     *  should be ordered so that each diff appears before any diff
     *  that depends on it.
     */
     *  should be ordered so that each diff appears before any diff
     *  that depends on it.
     */
-   pkgAcqIndexDiffs(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+   pkgAcqIndexDiffs(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
                     IndexTarget const &Target,
                    std::vector<DiffInfo> const &diffs=std::vector<DiffInfo>());
    virtual ~pkgAcqIndexDiffs();
                     IndexTarget const &Target,
                    std::vector<DiffInfo> const &diffs=std::vector<DiffInfo>());
    virtual ~pkgAcqIndexDiffs();
@@ -941,7 +942,7 @@ class APT_HIDDEN pkgAcqIndex : public pkgAcqBaseIndex
    virtual std::string DescURI() const {return Desc.URI;};
    virtual std::string GetMetaKey() const;
 
    virtual std::string DescURI() const {return Desc.URI;};
    virtual std::string GetMetaKey() const;
 
-   pkgAcqIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+   pkgAcqIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
                IndexTarget const &Target);
    virtual ~pkgAcqIndex();
 
                IndexTarget const &Target);
    virtual ~pkgAcqIndex();
 
index 8d619e96da9a1daed290d04cbab56712f0aa38fd..c0f93f9ce5305a9e1f44afe808135e187f98402a 100644 (file)
@@ -722,7 +722,7 @@ void pkgAcquire::Worker::PrepareFiles(char const * const caller, pkgAcquire::Que
         unlink(Owner->DestFile.c_str());
         if (link(filename.c_str(), Owner->DestFile.c_str()) != 0)
         {
         unlink(Owner->DestFile.c_str());
         if (link(filename.c_str(), Owner->DestFile.c_str()) != 0)
         {
-           // diferent mounts can't happen for us as we download to lists/ by default,
+           // different mounts can't happen for us as we download to lists/ by default,
            // but if the system is reused by others the locations can potentially be on
            // different disks, so use symlink as poor-men replacement.
            // FIXME: Real copying as last fallback, but that is costly, so offload to a method preferable
            // but if the system is reused by others the locations can potentially be on
            // different disks, so use symlink as poor-men replacement.
            // FIXME: Real copying as last fallback, but that is costly, so offload to a method preferable
index ea3d454806223943e2902ebef8e1eb2071ec44b7..690776266c96e3d5741688f1b2632fe605300bc8 100644 (file)
@@ -65,8 +65,8 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
 
    if (_config->FindB("pkgCacheFile::Generate", true) == false)
    {
 
    if (_config->FindB("pkgCacheFile::Generate", true) == false)
    {
-      Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
-                    FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
+      FileFd file(_config->FindFile("Dir::Cache::pkgcache"), FileFd::ReadOnly);
+      Map = new MMap(file, MMap::Public|MMap::ReadOnly);
       Cache = new pkgCache(Map);
       if (_error->PendingError() == true)
          return false;
       Cache = new pkgCache(Map);
       if (_error->PendingError() == true)
          return false;
index 6eb917457c62c9c45d5dafee59955385ae3113c5..428ef01616383b210ac1981b0e4d44fef38cf1ec 100644 (file)
@@ -287,9 +287,11 @@ string FindMountPointForDevice(const char *devnode)
            fclose(f);
            // unescape the \0XXX chars in the path
            string mount_point = out[1];
            fclose(f);
            // unescape the \0XXX chars in the path
            string mount_point = out[1];
+           free(line);
            return DeEscapeString(mount_point);
         }
         fclose(f);
            return DeEscapeString(mount_point);
         }
         fclose(f);
+        free(line);
       }
 
    return string();
       }
 
    return string();
index 9d798cca986713faf5bbbeb9cc94ea9e799bfd24..a01e319eb3e8ea0b5a03be6c4f9f10110e1398af 100644 (file)
@@ -296,6 +296,8 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile,
       // all the rest is whitespace, unsigned garbage or additional message blocks we ignore
    }
    fclose(in);
       // all the rest is whitespace, unsigned garbage or additional message blocks we ignore
    }
    fclose(in);
+   if (buf != NULL)
+      free(buf);
 
    if (found_signature == true)
       return _error->Error("Signature in file %s wasn't closed", InFile.c_str());
 
    if (found_signature == true)
       return _error->Error("Signature in file %s wasn't closed", InFile.c_str());
index 026af077fbb4f48686b7145cf2592a17b6342bbb..5a517b290d02b1ec9abf51ac83887429be1fe998 100644 (file)
@@ -270,7 +270,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const
    // special case for --print-uris
    std::vector<IndexTarget> const targets = GetIndexTargets();
 #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map<std::string,std::string>())
    // special case for --print-uris
    std::vector<IndexTarget> const targets = GetIndexTargets();
 #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map<std::string,std::string>())
-   pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner,
+   pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner,
         APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
         targets, iR);
 #undef APT_TARGET
         APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
         targets, iR);
 #undef APT_TARGET
index 326102d08e2a7b6a1ced59dbe31d7aef226286f0..d78a7e2e0cd4394005f00238f8d1a54ba684c94f 100644 (file)
@@ -42,10 +42,14 @@ debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
 // RecordParser::Jump - Jump to a specific record                      /*{{{*/
 bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
 {
 // RecordParser::Jump - Jump to a specific record                      /*{{{*/
 bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
 {
+   if (Ver.end() == true)
+      return false;
    return Tags.Jump(Section,Ver->Offset);
 }
 bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
 {
    return Tags.Jump(Section,Ver->Offset);
 }
 bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
 {
+   if (Desc.end() == true)
+      return false;
    return Tags.Jump(Section,Desc->Offset);
 }
                                                                        /*}}}*/
    return Tags.Jump(Section,Desc->Offset);
 }
                                                                        /*}}}*/
index 1991a4a66186a0c035e2097b451fe4e3ef24724f..3594a6efe989980f5cc95062ae4e123334c7496e 100644 (file)
@@ -1484,6 +1484,10 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
              a != Args.end(); ++a)
            clog << *a << ' ';
         clog << endl;
              a != Args.end(); ++a)
            clog << *a << ' ';
         clog << endl;
+        for (std::vector<char *>::const_iterator p = Packages.begin();
+              p != Packages.end(); ++p)
+           free(*p);
+        Packages.clear();
         continue;
       }
       Args.push_back(NULL);
         continue;
       }
       Args.push_back(NULL);
index 5a93d826fe29de75447b678a9009ff9a6af1c878..03ba59460862590df5b02a9315da142eb5dc62c1 100644 (file)
@@ -278,4 +278,7 @@ indexRecords::indexRecords(const string &ExpectedDist) :
 {
 }
 
 {
 }
 
-indexRecords::~indexRecords() {}
+indexRecords::~indexRecords() {
+   for (std::map<std::string, checkSum*>::const_iterator S = Entries.begin(); S != Entries.end(); ++S)
+      delete S->second;
+}
index 4c5505bf30af0d53506dfba683aef0967cf7656b..6d7d8185b590bc6ec9f3f0a73ee18eda98c61f24 100644 (file)
@@ -34,8 +34,10 @@ class pkgTagFilePrivate
 public:
    void Reset(FileFd * const pFd, unsigned long long const pSize)
    {
 public:
    void Reset(FileFd * const pFd, unsigned long long const pSize)
    {
-      Fd = pFd;
+      if (Buffer != NULL)
+        free(Buffer);
       Buffer = NULL;
       Buffer = NULL;
+      Fd = pFd;
       Start = NULL;
       End = NULL;
       Done = false;
       Start = NULL;
       End = NULL;
       Done = false;
@@ -43,7 +45,7 @@ public:
       Size = pSize;
    }
 
       Size = pSize;
    }
 
-   pkgTagFilePrivate(FileFd * const pFd, unsigned long long const Size)
+   pkgTagFilePrivate(FileFd * const pFd, unsigned long long const Size) : Buffer(NULL)
    {
       Reset(pFd, Size);
    }
    {
       Reset(pFd, Size);
    }
@@ -54,6 +56,12 @@ public:
    bool Done;
    unsigned long long iOffset;
    unsigned long long Size;
    bool Done;
    unsigned long long iOffset;
    unsigned long long Size;
+
+   ~pkgTagFilePrivate()
+   {
+      if (Buffer != NULL)
+        free(Buffer);
+   }
 };
 
 class pkgTagSectionPrivate
 };
 
 class pkgTagSectionPrivate
@@ -127,7 +135,6 @@ void pkgTagFile::Init(FileFd * const pFd,unsigned long long Size)
 /* */
 pkgTagFile::~pkgTagFile()
 {
 /* */
 pkgTagFile::~pkgTagFile()
 {
-   free(d->Buffer);
    delete d;
 }
                                                                        /*}}}*/
    delete d;
 }
                                                                        /*}}}*/
index 23238d9795682009f20491f951e41fe7f0a2f948..d0d0c7a840b9eb04415fa35d17b3eb3f8357d0db 100644 (file)
@@ -136,7 +136,7 @@ class pkgTagSection
     *
     * @param File to write the section to
     * @param Order in which tags should appear in the file
     *
     * @param File to write the section to
     * @param Order in which tags should appear in the file
-    * @param Rewrite is a set of tags to be renamed, rewitten and/or removed
+    * @param Rewrite is a set of tags to be renamed, rewritten and/or removed
     * @return \b true if successful, otherwise \b false
     */
    bool Write(FileFd &File, char const * const * const Order = NULL, std::vector<Tag> const &Rewrite = std::vector<Tag>()) const;
     * @return \b true if successful, otherwise \b false
     */
    bool Write(FileFd &File, char const * const * const Order = NULL, std::vector<Tag> const &Rewrite = std::vector<Tag>()) const;
index 059c7637ef4613c176f9486b5927af97dbe4aaa9..0eb22b78822c3a06047a2a8a441ea161307e8270 100644 (file)
@@ -32,10 +32,15 @@ struct VersionSortDescriptionLocality
    bool operator () (const pkgCache::VerIterator &v_lhs, 
                      const pkgCache::VerIterator &v_rhs)
     {
    bool operator () (const pkgCache::VerIterator &v_lhs, 
                      const pkgCache::VerIterator &v_rhs)
     {
-        pkgCache::DescFile *A = v_lhs.TranslatedDescription().FileList();
-        pkgCache::DescFile *B = v_rhs.TranslatedDescription().FileList();
-        if (A == 0 && B == 0)
-           return false;
+       pkgCache::DescFile const *A = NULL;
+       pkgCache::DescFile const *B = NULL;
+       if (v_lhs->DescriptionList != 0)
+         A = v_lhs.TranslatedDescription().FileList();
+       if (v_rhs->DescriptionList != 0)
+         B = v_rhs.TranslatedDescription().FileList();
+
+       if (A == 0 && B == 0)
+         return false;
 
        if (A == 0)
           return true;
 
        if (A == 0)
           return true;
index 4e18030ab50c3659c4bd39234afb88e789748c47..9944ab002ed310b56a4c277ad3971bf747026cf9 100644 (file)
@@ -199,10 +199,12 @@ static std::string GetShortDescription(pkgCacheFile &CacheFile, pkgRecords &reco
    std::string ShortDescription = "(none)";
    if(ver)
    {
    std::string ShortDescription = "(none)";
    if(ver)
    {
-      pkgCache::DescIterator Desc = ver.TranslatedDescription();
-      pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
-
-      ShortDescription = parser.ShortDesc();
+      pkgCache::DescIterator const Desc = ver.TranslatedDescription();
+      if (Desc.end() == false)
+      {
+        pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
+        ShortDescription = parser.ShortDesc();
+      }
    }
    return ShortDescription;
 }
    }
    return ShortDescription;
 }
@@ -222,11 +224,14 @@ static std::string GetLongDescription(pkgCacheFile &CacheFile, pkgRecords &recor
       return EmptyDescription;
 
    pkgCache::DescIterator const Desc = ver.TranslatedDescription();
       return EmptyDescription;
 
    pkgCache::DescIterator const Desc = ver.TranslatedDescription();
-   pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
-   std::string const longdesc = parser.LongDesc();
-   if (longdesc.empty() == true)
-      return EmptyDescription;
-   return SubstVar(longdesc, "\n ", "\n  ");
+   if (Desc.end() == false)
+   {
+      pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
+      std::string const longdesc = parser.LongDesc();
+      if (longdesc.empty() == false)
+        return SubstVar(longdesc, "\n ", "\n  ");
+   }
+   return EmptyDescription;
 }
                                                                        /*}}}*/
 void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records,   /*{{{*/
 }
                                                                        /*}}}*/
 void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records,   /*{{{*/
index 0dff02e69e5d174873a4dc6951362cde0fe7b768..8ea7a05ba16d560668d94933d07ca25eed24f07b 100644 (file)
@@ -16,6 +16,8 @@ CXXFLAGS+= -Wctor-dtor-privacy -Wdisabled-optimization -Winit-self -Wmissing-inc
 #CXXFLAGS+= -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn
 # gcc reports currently lots of them at the end of file - unknown reason
 CXXFLAGS+= -Wno-deprecated-declarations
 #CXXFLAGS+= -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn
 # gcc reports currently lots of them at the end of file - unknown reason
 CXXFLAGS+= -Wno-deprecated-declarations
+# sanitize options to be enabled for testing
+#CXXFLAGS+= -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr
 # a bit too pedantic to be run by default
 #CXXFLAGS+= -Wpedantic -Wno-long-long -Wno-vla -Wno-variadic-macros
 NUM_PROCS = @NUM_PROCS@
 # a bit too pedantic to be run by default
 #CXXFLAGS+= -Wpedantic -Wno-long-long -Wno-vla -Wno-variadic-macros
 NUM_PROCS = @NUM_PROCS@
index 303605f7029468caf23917630795577466e817ec..9c884433c8be4c19e7c96337d0c55eb21256becd 100644 (file)
@@ -1484,6 +1484,7 @@ static bool Search(CommandLine &CmdL)
    delete [] PatternMatch;
    for (unsigned I = 0; I != NumPatterns; I++)
       regfree(&Patterns[I]);
    delete [] PatternMatch;
    for (unsigned I = 0; I != NumPatterns; I++)
       regfree(&Patterns[I]);
+   delete [] Patterns;
    if (ferror(stdout))
        return _error->Error("Write to stdout failed");
    return true;
    if (ferror(stdout))
        return _error->Error("Write to stdout failed");
    return true;
index 184b51d23cbf1a2d74419fcbd5fc033cc1cdefc2..632c7cfeab881ad8ea9e53fd171c3a0a38bab372 100644 (file)
@@ -1015,9 +1015,6 @@ static bool DoBuildDep(CommandLine &CmdL)
    pkgSourceList *List = Cache.GetSourceList();
    
    // Create the text record parsers
    pkgSourceList *List = Cache.GetSourceList();
    
    // Create the text record parsers
-#if APT_PKG_ABI < 413
-   pkgRecords Recs(Cache);
-#endif
    pkgSrcRecords SrcRecs(*List);
    if (_error->PendingError() == true)
       return false;
    pkgSrcRecords SrcRecs(*List);
    if (_error->PendingError() == true)
       return false;
@@ -1039,6 +1036,7 @@ static bool DoBuildDep(CommandLine &CmdL)
    {
       string Src;
       pkgSrcRecords::Parser *Last = 0;
    {
       string Src;
       pkgSrcRecords::Parser *Last = 0;
+      SPtr<pkgSrcRecords::Parser> LastOwner;
 
       // an unpacked debian source tree
       using APT::String::Startswith;
 
       // an unpacked debian source tree
       using APT::String::Startswith;
@@ -1050,7 +1048,7 @@ static bool DoBuildDep(CommandLine &CmdL)
          std::string TypeName = "debian/control File Source Index";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          if(Type != NULL)
          std::string TypeName = "debian/control File Source Index";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          if(Type != NULL)
-            Last = Type->CreateSrcPkgParser(*I);
+            LastOwner = Last = Type->CreateSrcPkgParser(*I);
       }
       // if its a local file (e.g. .dsc) use this
       else if (FileExists(*I))
       }
       // if its a local file (e.g. .dsc) use this
       else if (FileExists(*I))
@@ -1061,7 +1059,7 @@ static bool DoBuildDep(CommandLine &CmdL)
          string TypeName = flExtension(*I) + " File Source Index";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          if(Type != NULL)
          string TypeName = flExtension(*I) + " File Source Index";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          if(Type != NULL)
-            Last = Type->CreateSrcPkgParser(*I);
+            LastOwner = Last = Type->CreateSrcPkgParser(*I);
       } else {
          // normal case, search the cache for the source file
 #if APT_PKG_ABI >= 413
       } else {
          // normal case, search the cache for the source file
 #if APT_PKG_ABI >= 413
index 62108f7ca959cad4a7d86f1faef237c0c8155543..cf667483c6494b4852832bddc45966e39c758be2 100644 (file)
@@ -180,7 +180,7 @@ bool PackageMap::GenPackages(Configuration &Setup,struct CacheDB::Stats &Stats)
    // Create a package writer object.
    MultiCompress Comp(flCombine(ArchiveDir,PkgFile),
                      PkgCompress,Permissions);
    // Create a package writer object.
    MultiCompress Comp(flCombine(ArchiveDir,PkgFile),
                      PkgCompress,Permissions);
-   PackagesWriter Packages(&Comp.Input, flCombine(CacheDir,BinCacheDB),
+   PackagesWriter Packages(&Comp.Input, TransWriter, flCombine(CacheDir,BinCacheDB),
                           flCombine(OverrideDir,BinOverride),
                           flCombine(OverrideDir,ExtraOverride),
                           Arch);
                           flCombine(OverrideDir,BinOverride),
                           flCombine(OverrideDir,ExtraOverride),
                           Arch);
@@ -193,7 +193,6 @@ bool PackageMap::GenPackages(Configuration &Setup,struct CacheDB::Stats &Stats)
    Packages.DirStrip = ArchiveDir;
    Packages.InternalPrefix = flCombine(ArchiveDir,InternalPrefix);
 
    Packages.DirStrip = ArchiveDir;
    Packages.InternalPrefix = flCombine(ArchiveDir,InternalPrefix);
 
-   Packages.TransWriter = TransWriter;
    Packages.LongDescription = LongDesc;
 
    Packages.Stats.DeLinkBytes = Stats.DeLinkBytes;
    Packages.LongDescription = LongDesc;
 
    Packages.Stats.DeLinkBytes = Stats.DeLinkBytes;
@@ -457,7 +456,7 @@ bool PackageMap::GenContents(Configuration &Setup,
 // ---------------------------------------------------------------------
 /* This populates the PkgList with all the possible permutations of the
    section/arch lists. */
 // ---------------------------------------------------------------------
 /* This populates the PkgList with all the possible permutations of the
    section/arch lists. */
-static void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup)
+static void LoadTree(vector<PackageMap> &PkgList, std::vector<TranslationWriter*> &TransList, Configuration &Setup)
 {   
    // Load the defaults
    string DDir = Setup.Find("TreeDefault::Directory",
 {   
    // Load the defaults
    string DDir = Setup.Find("TreeDefault::Directory",
@@ -508,16 +507,7 @@ static void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup)
                                         {NULL, NULL}};
         mode_t const Perms = Block.FindI("FileMode", Permissions);
         bool const LongDesc = Block.FindB("LongDescription", LongDescription);
                                         {NULL, NULL}};
         mode_t const Perms = Block.FindI("FileMode", Permissions);
         bool const LongDesc = Block.FindB("LongDescription", LongDescription);
-        TranslationWriter *TransWriter;
-        if (DTrans.empty() == false && LongDesc == false)
-        {
-           string const TranslationFile = flCombine(Setup.FindDir("Dir::ArchiveDir"),
-                       SubstVar(Block.Find("Translation", DTrans.c_str()), Vars));
-           string const TransCompress = Block.Find("Translation::Compress", TranslationCompress);
-           TransWriter = new TranslationWriter(TranslationFile, TransCompress, Perms);
-        }
-        else
-           TransWriter = NULL;
+        TranslationWriter *TransWriter = NULL;
 
         string const Tmp2 = Block.Find("Architectures");
         const char *Archs = Tmp2.c_str();
 
         string const Tmp2 = Block.Find("Architectures");
         const char *Archs = Tmp2.c_str();
@@ -546,27 +536,34 @@ static void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup)
               Itm.Tag = SubstVar("$(DIST)/$(SECTION)/$(ARCH)",Vars);
               Itm.Arch = Arch;
               Itm.LongDesc = LongDesc;
               Itm.Tag = SubstVar("$(DIST)/$(SECTION)/$(ARCH)",Vars);
               Itm.Arch = Arch;
               Itm.LongDesc = LongDesc;
-              if (TransWriter != NULL)
+              if (TransWriter == NULL && DTrans.empty() == false && LongDesc == false && DTrans != "/dev/null")
               {
               {
-                 TransWriter->IncreaseRefCounter();
-                 Itm.TransWriter = TransWriter;
+                 string const TranslationFile = flCombine(Setup.FindDir("Dir::ArchiveDir"),
+                       SubstVar(Block.Find("Translation", DTrans.c_str()), Vars));
+                 string const TransCompress = Block.Find("Translation::Compress", TranslationCompress);
+                 TransWriter = new TranslationWriter(TranslationFile, TransCompress, Perms);
+                 TransList.push_back(TransWriter);
               }
               }
+              Itm.TransWriter = TransWriter;
               Itm.Contents = SubstVar(Block.Find("Contents",DContents.c_str()),Vars);
               Itm.ContentsHead = SubstVar(Block.Find("Contents::Header",DContentsH.c_str()),Vars);
               Itm.FLFile = SubstVar(Block.Find("FileList",DFLFile.c_str()),Vars);
               Itm.ExtraOverride = SubstVar(Block.Find("ExtraOverride"),Vars);
            }
 
               Itm.Contents = SubstVar(Block.Find("Contents",DContents.c_str()),Vars);
               Itm.ContentsHead = SubstVar(Block.Find("Contents::Header",DContentsH.c_str()),Vars);
               Itm.FLFile = SubstVar(Block.Find("FileList",DFLFile.c_str()),Vars);
               Itm.ExtraOverride = SubstVar(Block.Find("ExtraOverride"),Vars);
            }
 
-           Itm.GetGeneral(Setup,Block);
+           Itm.GetGeneral(Setup,Block);
            PkgList.push_back(Itm);
         }
            PkgList.push_back(Itm);
         }
-        // we didn't use this TransWriter, so we can release it
-        if (TransWriter != NULL && TransWriter->GetRefCounter() == 0)
-           delete TransWriter;
       }
       }
-      
+
       Top = Top->Next;
       Top = Top->Next;
-   }      
+   }
+}
+                                                                       /*}}}*/
+static void UnloadTree(std::vector<TranslationWriter*> const &Trans)           /*{{{*/
+{
+   for (std::vector<TranslationWriter*>::const_reverse_iterator T = Trans.rbegin(); T != Trans.rend(); ++T)
+      delete *T;
 }
                                                                        /*}}}*/
 // LoadBinDir - Load a 'bindirectory' section from the Generate Config /*{{{*/
 }
                                                                        /*}}}*/
 // LoadBinDir - Load a 'bindirectory' section from the Generate Config /*{{{*/
@@ -671,7 +668,7 @@ static bool SimpleGenPackages(CommandLine &CmdL)
       Override = CmdL.FileList[2];
    
    // Create a package writer object.
       Override = CmdL.FileList[2];
    
    // Create a package writer object.
-   PackagesWriter Packages(NULL, _config->Find("APT::FTPArchive::DB"),
+   PackagesWriter Packages(NULL, NULL, _config->Find("APT::FTPArchive::DB"),
                           Override, "", _config->Find("APT::FTPArchive::Architecture"));
    if (_error->PendingError() == true)
       return false;
                           Override, "", _config->Find("APT::FTPArchive::Architecture"));
    if (_error->PendingError() == true)
       return false;
@@ -844,12 +841,6 @@ static bool DoGeneratePackagesAndSources(Configuration &Setup,
       
       delete [] List;
    }
       
       delete [] List;
    }
-
-   // close the Translation master files
-   for (vector<PackageMap>::reverse_iterator I = PkgList.rbegin(); I != PkgList.rend(); ++I)
-      if (I->TransWriter != NULL && I->TransWriter->DecreaseRefCounter() == 0)
-        delete I->TransWriter;
-
    return true;
 }
 
    return true;
 }
 
@@ -940,7 +931,8 @@ static bool Generate(CommandLine &CmdL)
       return false;
 
    vector<PackageMap> PkgList;
       return false;
 
    vector<PackageMap> PkgList;
-   LoadTree(PkgList,Setup);
+   std::vector<TranslationWriter*> TransList;
+   LoadTree(PkgList, TransList, Setup);
    LoadBinDir(PkgList,Setup);
 
    // Sort by cache DB to improve IO locality.
    LoadBinDir(PkgList,Setup);
 
    // Sort by cache DB to improve IO locality.
@@ -951,7 +943,10 @@ static bool Generate(CommandLine &CmdL)
    if (_config->FindB("APT::FTPArchive::ContentsOnly", false) == false)
    {
       if(DoGeneratePackagesAndSources(Setup, PkgList, SrcStats, Stats, CmdL) == false)
    if (_config->FindB("APT::FTPArchive::ContentsOnly", false) == false)
    {
       if(DoGeneratePackagesAndSources(Setup, PkgList, SrcStats, Stats, CmdL) == false)
+      {
+        UnloadTree(TransList);
          return false;
          return false;
+      }
    } else {
       c1out << "Skipping Packages/Sources generation" << endl;
    }
    } else {
       c1out << "Skipping Packages/Sources generation" << endl;
    }
@@ -959,7 +954,10 @@ static bool Generate(CommandLine &CmdL)
    // do Contents if needed
    if (_config->FindB("APT::FTPArchive::Contents", true) == true)
       if (DoGenerateContents(Setup, PkgList, CmdL) == false)
    // do Contents if needed
    if (_config->FindB("APT::FTPArchive::Contents", true) == true)
       if (DoGenerateContents(Setup, PkgList, CmdL) == false)
-         return false;
+      {
+        UnloadTree(TransList);
+        return false;
+      }
 
    struct timeval NewTime;
    gettimeofday(&NewTime,0);
 
    struct timeval NewTime;
    gettimeofday(&NewTime,0);
@@ -968,6 +966,7 @@ static bool Generate(CommandLine &CmdL)
    c1out << "Done. " << SizeToStr(Stats.Bytes) << "B in " << Stats.Packages
          << " archives. Took " << TimeToStr((long)Delta) << endl;
 
    c1out << "Done. " << SizeToStr(Stats.Bytes) << "B in " << Stats.Packages
          << " archives. Took " << TimeToStr((long)Delta) << endl;
 
+   UnloadTree(TransList);
    return true;
 }
 
    return true;
 }
 
@@ -984,9 +983,12 @@ static bool Clean(CommandLine &CmdL)
    Configuration Setup;
    if (ReadConfigFile(Setup,CmdL.FileList[1],true) == false)
       return false;
    Configuration Setup;
    if (ReadConfigFile(Setup,CmdL.FileList[1],true) == false)
       return false;
+   // we don't need translation creation here
+   Setup.Set("TreeDefault::Translation", "/dev/null");
 
    vector<PackageMap> PkgList;
 
    vector<PackageMap> PkgList;
-   LoadTree(PkgList,Setup);
+   std::vector<TranslationWriter*> TransList;
+   LoadTree(PkgList, TransList, Setup);
    LoadBinDir(PkgList,Setup);
 
    // Sort by cache DB to improve IO locality.
    LoadBinDir(PkgList,Setup);
 
    // Sort by cache DB to improve IO locality.
@@ -1007,14 +1009,13 @@ static bool Clean(CommandLine &CmdL)
         _error->DumpErrors();
       if (DB_SRC.Clean() == false)
         _error->DumpErrors();
         _error->DumpErrors();
       if (DB_SRC.Clean() == false)
         _error->DumpErrors();
-      
+
       string CacheDB = I->BinCacheDB;
       string SrcCacheDB = I->SrcCacheDB;
       while(I != PkgList.end() && 
             I->BinCacheDB == CacheDB && 
             I->SrcCacheDB == SrcCacheDB)
          ++I;
       string CacheDB = I->BinCacheDB;
       string SrcCacheDB = I->SrcCacheDB;
       while(I != PkgList.end() && 
             I->BinCacheDB == CacheDB && 
             I->SrcCacheDB == SrcCacheDB)
          ++I;
-
    }
 
   
    }
 
   
index cc3527ea40fa68c575a989dbfea11fb394dbf75d..ce6c865f334f9a9613717edebce81cf99891a4f1 100644 (file)
@@ -45,6 +45,7 @@ CacheDB::~CacheDB()
 {
    ReadyDB();
    delete DebFile;
 {
    ReadyDB();
    delete DebFile;
+   CloseFile();
 }
 
 // CacheDB::ReadyDB - Ready the DB2                                    /*{{{*/
 }
 
 // CacheDB::ReadyDB - Ready the DB2                                    /*{{{*/
index 7cf7e6efc778577ccabc7cf60305a26bf570222a..1bc926d2157dcea06f457b7dc89d435f7e21862f 100644 (file)
@@ -69,22 +69,29 @@ static void ConfigToDoHashes(unsigned int &DoHashes, std::string const &Conf)
                                                                        /*}}}*/
 
 // FTWScanner::FTWScanner - Constructor                                        /*{{{*/
                                                                        /*}}}*/
 
 // FTWScanner::FTWScanner - Constructor                                        /*{{{*/
-// ---------------------------------------------------------------------
-/* */
 FTWScanner::FTWScanner(FileFd * const GivenOutput, string const &Arch): Arch(Arch), DoHashes(~0)
 {
    if (GivenOutput == NULL)
    {
       Output = new FileFd;
 FTWScanner::FTWScanner(FileFd * const GivenOutput, string const &Arch): Arch(Arch), DoHashes(~0)
 {
    if (GivenOutput == NULL)
    {
       Output = new FileFd;
+      OwnsOutput = true;
       Output->OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
    }
    else
       Output->OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
    }
    else
+   {
       Output = GivenOutput;
       Output = GivenOutput;
+      OwnsOutput = false;
+   }
    ErrorPrinted = false;
    NoLinkAct = !_config->FindB("APT::FTPArchive::DeLinkAct",true);
    ConfigToDoHashes(DoHashes, "APT::FTPArchive");
 }
                                                                        /*}}}*/
    ErrorPrinted = false;
    NoLinkAct = !_config->FindB("APT::FTPArchive::DeLinkAct",true);
    ConfigToDoHashes(DoHashes, "APT::FTPArchive");
 }
                                                                        /*}}}*/
+FTWScanner::~FTWScanner()
+{
+   if (Output != NULL && OwnsOutput)
+      delete Output;
+}
 // FTWScanner::Scanner - FTW Scanner                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* This is the FTW scanner, it processes each directory element in the
 // FTWScanner::Scanner - FTW Scanner                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* This is the FTW scanner, it processes each directory element in the
@@ -324,9 +331,10 @@ bool FTWScanner::Delink(string &FileName,const char *OriginalPath,
 // PackagesWriter::PackagesWriter - Constructor                                /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // PackagesWriter::PackagesWriter - Constructor                                /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-PackagesWriter::PackagesWriter(FileFd * const GivenOutput, string const &DB,string const &Overrides,string const &ExtOverrides,
-                              string const &Arch) :
-   FTWScanner(GivenOutput, Arch), Db(DB), Stats(Db.Stats), TransWriter(NULL)
+PackagesWriter::PackagesWriter(FileFd * const GivenOutput, TranslationWriter * const transWriter,
+      string const &DB,string const &Overrides,string const &ExtOverrides,
+      string const &Arch) :
+   FTWScanner(GivenOutput, Arch), Db(DB), Stats(Db.Stats), TransWriter(transWriter)
 {
    SetExts(".deb .udeb");
    DeLinkLimit = 0;
 {
    SetExts(".deb .udeb");
    DeLinkLimit = 0;
@@ -377,7 +385,6 @@ bool FTWScanner::SetExts(string const &Vals)
 
    return true;
 }
 
    return true;
 }
-
                                                                        /*}}}*/
 // PackagesWriter::DoPackage - Process a single package                        /*{{{*/
 // ---------------------------------------------------------------------
                                                                        /*}}}*/
 // PackagesWriter::DoPackage - Process a single package                        /*{{{*/
 // ---------------------------------------------------------------------
@@ -524,12 +531,16 @@ bool PackagesWriter::DoPackage(string FileName)
    return Db.Finish();
 }
                                                                        /*}}}*/
    return Db.Finish();
 }
                                                                        /*}}}*/
+PackagesWriter::~PackagesWriter()                                      /*{{{*/
+{
+}
+                                                                       /*}}}*/
 
 // TranslationWriter::TranslationWriter - Constructor                  /*{{{*/
 // ---------------------------------------------------------------------
 /* Create a Translation-Master file for this Packages file */
 TranslationWriter::TranslationWriter(string const &File, string const &TransCompress,
 
 // TranslationWriter::TranslationWriter - Constructor                  /*{{{*/
 // ---------------------------------------------------------------------
 /* Create a Translation-Master file for this Packages file */
 TranslationWriter::TranslationWriter(string const &File, string const &TransCompress,
-                                       mode_t const &Permissions) : RefCounter(0)
+                                       mode_t const &Permissions) : Comp(NULL), Output(NULL)
 {
    if (File.empty() == true)
       return;
 {
    if (File.empty() == true)
       return;
@@ -568,10 +579,8 @@ bool TranslationWriter::DoPackage(string const &Pkg, string const &Desc,
 /* */
 TranslationWriter::~TranslationWriter()
 {
 /* */
 TranslationWriter::~TranslationWriter()
 {
-   if (Comp == NULL)
-      return;
-
-   delete Comp;
+   if (Comp != NULL)
+      delete Comp;
 }
                                                                        /*}}}*/
 
 }
                                                                        /*}}}*/
 
index 0ba60db5e646587fc2ebe64f93670b47e112b979..b9c1f672a3dcecedd49b8f577851603a590211d7 100644 (file)
@@ -64,6 +64,7 @@ class FTWScanner
 
    public:
    FileFd *Output;
 
    public:
    FileFd *Output;
+   bool OwnsOutput;
    unsigned int DoHashes;
 
    unsigned long DeLinkLimit;
    unsigned int DoHashes;
 
    unsigned long DeLinkLimit;
@@ -79,7 +80,7 @@ class FTWScanner
    bool SetExts(string const &Vals);
 
    FTWScanner(FileFd * const Output, string const &Arch = string());
    bool SetExts(string const &Vals);
 
    FTWScanner(FileFd * const Output, string const &Arch = string());
-   virtual ~FTWScanner() {};
+   virtual ~FTWScanner();
 };
 
 class MultiCompress;
 };
 
 class MultiCompress;
@@ -88,17 +89,12 @@ class TranslationWriter
 {
    MultiCompress *Comp;
    std::set<string> Included;
 {
    MultiCompress *Comp;
    std::set<string> Included;
-   unsigned short RefCounter;
    FileFd *Output;
 
    public:
    FileFd *Output;
 
    public:
-   void IncreaseRefCounter() { ++RefCounter; };
-   unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
-   unsigned short GetRefCounter() const { return RefCounter; };
    bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
 
    TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
    bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
 
    TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
-   TranslationWriter() : Comp(NULL), RefCounter(0) {};
    ~TranslationWriter();
 };
 
    ~TranslationWriter();
 };
 
@@ -119,18 +115,18 @@ class PackagesWriter : public FTWScanner
    string PathPrefix;
    string DirStrip;
    struct CacheDB::Stats &Stats;
    string PathPrefix;
    string DirStrip;
    struct CacheDB::Stats &Stats;
-   TranslationWriter *TransWriter;
+   TranslationWriter * const TransWriter;
 
    inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
    inline bool ReadExtraOverride(string const &File) 
       {return Over.ReadExtraOverride(File);};
    virtual bool DoPackage(string FileName);
 
 
    inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
    inline bool ReadExtraOverride(string const &File) 
       {return Over.ReadExtraOverride(File);};
    virtual bool DoPackage(string FileName);
 
-   PackagesWriter(FileFd * const Output, string const &DB,
+   PackagesWriter(FileFd * const Output, TranslationWriter * const TransWriter, string const &DB,
                   string const &Overrides,
                   string const &ExtOverrides = "",
                  string const &Arch = "");
                   string const &Overrides,
                   string const &ExtOverrides = "",
                  string const &Arch = "");
-   virtual ~PackagesWriter() {};
+   virtual ~PackagesWriter();
 };
 
 class ContentsWriter : public FTWScanner
 };
 
 class ContentsWriter : public FTWScanner
index 5d949009fc61e0f117459526e10e4ec8765ef986..059cba9fb54ffd6d2b5a2e9b100c62be31be7bf2 100644 (file)
@@ -143,6 +143,7 @@ gdb() {
        aptcache) CMD="apt-cache";;
        aptmark) CMD="apt-mark";;
        apthelper) CMD="apt-helper";;
        aptcache) CMD="apt-cache";;
        aptmark) CMD="apt-mark";;
        apthelper) CMD="apt-helper";;
+       aptftparchive) CMD="apt-ftparchive";;
        *) CMD="$1";;
        esac
        shift
        *) CMD="$1";;
        esac
        shift
@@ -1415,6 +1416,8 @@ testfailure() {
                if expr match "$1" '^apt.*' >/dev/null; then
                        if grep -q -E ' runtime error: ' "$OUTPUT"; then
                                msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
                if expr match "$1" '^apt.*' >/dev/null; then
                        if grep -q -E ' runtime error: ' "$OUTPUT"; then
                                msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
+                       elif grep -q -E '==ERROR' "$OUTPUT"; then
+                               msgfailoutput 'compiler sanitizers reported errors' "$OUTPUT" "$@"
                        elif ! grep -q -E '^E: ' "$OUTPUT"; then
                                msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
                        else
                        elif ! grep -q -E '^E: ' "$OUTPUT"; then
                                msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
                        else
index 7257eaf1b5aabb4179641ed949cda9f3f356346b..b4c51cdb0452ca52ae9438c1cc6a85caddaab9c1 100644 (file)
@@ -91,7 +91,7 @@ TEST(CDROMTest,ReduceSourcelist)
 }
 TEST(CDROMTest, FindMountPointForDevice)
 {
 }
 TEST(CDROMTest, FindMountPointForDevice)
 {
-   char * tempfile = NULL;
+   std::string tempfile;
    FileFd fd;
    createTemporaryFile("mountpoints", fd, &tempfile,
         "rootfs / rootfs rw 0 0\n"
    FileFd fd;
    createTemporaryFile("mountpoints", fd, &tempfile,
         "rootfs / rootfs rw 0 0\n"
@@ -109,7 +109,6 @@ TEST(CDROMTest, FindMountPointForDevice)
    EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1"));
    EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs"));
 
    EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1"));
    EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs"));
 
-   if (tempfile !=  NULL)
-      unlink(tempfile);
-   free(tempfile);
+   if (tempfile.empty() == false)
+      unlink(tempfile.c_str());
 }
 }
index 5edb9a9fead18491e86731a7f49a473a49988150..3871928685cd33d5563593707d52b938de631ce4 100644 (file)
@@ -53,20 +53,19 @@ void helperCreateLink(std::string const &dir, std::string const &targetname, std
    link.append(linkname);
    ASSERT_EQ(0, symlink(target.c_str(), link.c_str()));
 }
    link.append(linkname);
    ASSERT_EQ(0, symlink(target.c_str(), link.c_str()));
 }
-void helperCreateTemporaryFile(std::string const &id, FileFd &fd, char * * const filename, char const * const content)
+void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content)
 {
    std::string name("apt-test-");
    name.append(id).append(".XXXXXXXX");
    char * tempfile = strdup(name.c_str());
 {
    std::string name("apt-test-");
    name.append(id).append(".XXXXXXXX");
    char * tempfile = strdup(name.c_str());
+   ASSERT_STRNE(NULL, tempfile);
    int tempfile_fd = mkstemp(tempfile);
    ASSERT_NE(-1, tempfile_fd);
    if (filename != NULL)
       *filename = tempfile;
    else
    int tempfile_fd = mkstemp(tempfile);
    ASSERT_NE(-1, tempfile_fd);
    if (filename != NULL)
       *filename = tempfile;
    else
-   {
       unlink(tempfile);
       unlink(tempfile);
-      free(tempfile);
-   }
+   free(tempfile);
 
    EXPECT_TRUE(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite));
    if (content != NULL)
 
    EXPECT_TRUE(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite));
    if (content != NULL)
index e8472d503b92ac7a5f443087724b7087dc96f35f..f639c1cbcb3a76441850583a9ccdd671231775ff 100644 (file)
@@ -24,6 +24,6 @@ void helperCreateDirectory(std::string const &dir, std::string const &name);
 void helperCreateLink(std::string const &dir, std::string const &targetname, std::string const &linkname);
 #define createTemporaryFile(id, fd, filename, content) \
    ASSERT_NO_FATAL_FAILURE(helperCreateTemporaryFile(id, fd, filename, content))
 void helperCreateLink(std::string const &dir, std::string const &targetname, std::string const &linkname);
 #define createTemporaryFile(id, fd, filename, content) \
    ASSERT_NO_FATAL_FAILURE(helperCreateTemporaryFile(id, fd, filename, content))
-void helperCreateTemporaryFile(std::string const &id, FileFd &fd, char * * const filename, char const * const content);
+void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content);
 
 #endif
 
 #endif
index 747ab4957f7eb374616ef00b1a6251aeb433ee63..9e6f822133f0b1d61c6690e74ee94650db762d69 100644 (file)
@@ -20,7 +20,7 @@ class SourceList : public pkgSourceList {
 TEST(SourceListTest,ParseFileDeb822)
 {
    FileFd fd;
 TEST(SourceListTest,ParseFileDeb822)
 {
    FileFd fd;
-   char * tempfile = NULL;
+   std::string tempfile;
    createTemporaryFile("parsefiledeb822", fd, &tempfile,
       "Types: deb\n"
       "URIs: http://ftp.debian.org/debian\n"
    createTemporaryFile("parsefiledeb822", fd, &tempfile,
       "Types: deb\n"
       "URIs: http://ftp.debian.org/debian\n"
@@ -39,5 +39,6 @@ TEST(SourceListTest,ParseFileDeb822)
    EXPECT_EQ(2, sources.ParseFileDeb822(tempfile));
    EXPECT_EQ(2, sources.size());
 
    EXPECT_EQ(2, sources.ParseFileDeb822(tempfile));
    EXPECT_EQ(2, sources.size());
 
-   unlink(tempfile);
+   if (tempfile.empty() == false)
+      unlink(tempfile.c_str());
 }
 }