]> git.cworth.org Git - apitrace/commitdiff
Don't call overridden virtual methods from the base destructor.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 27 Nov 2011 12:18:24 +0000 (12:18 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 27 Nov 2011 12:45:21 +0000 (12:45 +0000)
It causes the program to terminate with "pure virtual method called"
error, as the derived class members are no longer accessible.

common/trace_file.cpp
common/trace_file_snappy.cpp
common/trace_file_zlib.cpp

index 22106026327f1e1e5572cf06585fcd9ebfad36c1..3657fd2943088012fa4c69abc790bb753a151f8e 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <assert.h>
 
+
 using namespace trace;
 
 
@@ -43,7 +44,8 @@ File::File(const std::string &filename,
 
 File::~File()
 {
-    close();
+    // We can't invoke any overriden virtual method here anymore
+    assert(!m_isOpened);
 }
 
 
index 4d4ecea7a73c8f4251a59116af61b7636db78402..5901bfb33f0b312b6fb78d00278283fd37c87d2f 100644 (file)
@@ -141,6 +141,7 @@ SnappyFile::SnappyFile(const std::string &filename,
 
 SnappyFile::~SnappyFile()
 {
+    close();
     delete [] m_compressedCache;
     delete [] m_cache;
 }
index 92cead9188862ddb57d4bf74d79e14082680eac2..b299b5a6bd2879fdaec8937d493ab8a7e64694f9 100644 (file)
@@ -73,6 +73,7 @@ ZLibFile::ZLibFile(const std::string &filename,
 
 ZLibFile::~ZLibFile()
 {
+    close();
 }
 
 bool ZLibFile::rawOpen(const std::string &filename, File::Mode mode)