]> git.saurik.com Git - apt.git/commitdiff
use free() instead of delete() when realloc is used
authorMichael Vogt <mvo@debian.org>
Tue, 27 May 2014 14:25:43 +0000 (16:25 +0200)
committerMichael Vogt <mvo@debian.org>
Tue, 27 May 2014 14:25:43 +0000 (16:25 +0200)
ContentsExtract::~ContentsExtract() needs to use free() because
Data got allocated via realloc()

Reported-By: clang -fsanitize=address -fno-omit-frame-pointer
apt-pkg/contrib/fileutl.cc
ftparchive/cachedb.cc
ftparchive/cachedb.h
ftparchive/contents.cc
ftparchive/contents.h
ftparchive/writer.h

index b77c7ff7fd153a2d3fc228d6e5850f5deb367fb1..bfd9581831f5917dbb0d1e51a2b67c42be7b7aed 100644 (file)
@@ -1241,7 +1241,8 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C
         if (d->lzma == NULL)
            d->lzma = new FileFdPrivate::LZMAFILE;
         d->lzma->file = (FILE*) compress_struct;
-        d->lzma->stream = LZMA_STREAM_INIT;
+         lzma_stream tmp_stream = LZMA_STREAM_INIT;
+        d->lzma->stream = tmp_stream;
 
         if ((Mode & ReadWrite) == ReadWrite)
            return FileFdError("ReadWrite mode is not supported for file %s", FileName.c_str());
index e56deae1e7556bebaff869164c8d826d5dd574e9..12eac20d8de24471c6a78d33e32fd3321ab694f0 100644 (file)
 #include <apti18n.h>
                                                                        /*}}}*/
 
+CacheDB::CacheDB(std::string const &DB) 
+   : Dbp(0), Fd(NULL), DebFile(0)
+{
+   TmpKey[0]='\0';
+   ReadyDB(DB);
+};
+
+CacheDB::~CacheDB()
+{
+   ReadyDB();
+   delete DebFile;
+};
+
 // CacheDB::ReadyDB - Ready the DB2                                    /*{{{*/
 // ---------------------------------------------------------------------
 /* This opens the DB2 file for caching package information */
index 54a27494487e8f8641376bcebe854b72a572bc6d..edb8594bf352cd742774ba569090c88f704b539d 100644 (file)
@@ -156,7 +156,7 @@ class CacheDB
                SHA512Bytes(0),Packages(0), Misses(0), DeLinkBytes(0) {};
    } Stats;
    
-   bool ReadyDB(std::string const &DB);
+   bool ReadyDB(std::string const &DB = "");
    inline bool DBFailed() {return Dbp != 0 && DBLoaded == false;};
    inline bool Loaded() {return DBLoaded == true;};
    
@@ -180,8 +180,8 @@ class CacheDB
    
    bool Clean();
    
-   CacheDB(std::string const &DB) : Dbp(0), Fd(NULL), DebFile(0) {TmpKey[0]='\0'; ReadyDB(DB);};
-   ~CacheDB() {ReadyDB(std::string()); delete DebFile;};
+   CacheDB(std::string const &DB);
+   ~CacheDB();
 };
     
 #endif
index 7a1fb779e8a46b339ecd8f9a4ee0ba19a1a85d12..91dd2b8bde68de0ed8d8859aee8debdabe810f5f 100644 (file)
@@ -302,7 +302,18 @@ void GenContents::DoPrint(FILE *Out,GenContents::Node *Top, char *Buf)
    DoPrint(Out,Top->BTreeRight,Buf);  
 }
                                                                        /*}}}*/
-
+// ContentsExtract Constructor                                         /*{{{*/
+ContentsExtract::ContentsExtract()
+   : Data(0), MaxSize(0), CurSize(0) 
+{
+};
+                                                                       /*}}}*/
+// ContentsExtract Destructor                                          /*{{{*/
+ContentsExtract::~ContentsExtract()
+{
+   free(Data);
+};
+                                                                       /*}}}*/
 // ContentsExtract::Read - Read the archive                            /*{{{*/
 // ---------------------------------------------------------------------
 /* */
index dbbb83350c8aa7913174f6d4691e0aa7e1138204..f58e3278ec14f9cd521bc1aea0cf8e93d2e129e8 100644 (file)
@@ -85,8 +85,8 @@ class ContentsExtract : public pkgDirStream
    bool TakeContents(const void *Data,unsigned long long Length);
    void Add(GenContents &Contents,std::string const &Package);
    
-   ContentsExtract() : Data(0), MaxSize(0), CurSize(0) {};
-   virtual ~ContentsExtract() {delete [] Data;};
+   ContentsExtract();
+   virtual ~ContentsExtract();
 };
 
 #endif
index b1a653e7daafc8c8cd6b5b5ea8389ba9c4ab9562..d8a10e0bbc578376139842bb63cdd48579bbc5cc 100644 (file)
@@ -127,8 +127,10 @@ class PackagesWriter : public FTWScanner
       {return Over.ReadExtraOverride(File);};
    virtual bool DoPackage(string FileName);
 
-   PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
-                 string const &Arch=string());
+   PackagesWriter(string const &DB,
+                  string const &Overrides,
+                  string const &ExtOverrides = "",
+                 string const &Arch = "");
    virtual ~PackagesWriter() {};
 };