Do no call virtual functions from destructor
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Wed, 13 Jun 2018 17:52:11 +0000 (20:52 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Wed, 13 Jun 2018 17:52:11 +0000 (20:52 +0300)
src/debug/netcoredbg/platform.cpp

index 330d501..cb8dbce 100644 (file)
@@ -204,14 +204,17 @@ public:
     typedef std::streambuf::traits_type traits_type;
 
     fdbuf(int fd);
-    ~fdbuf();
+    virtual ~fdbuf();
     void open(int fd);
     void close();
 
 protected:
-    int overflow(int c);
-    int underflow();
-    int sync();
+    int overflow(int c) override;
+    int underflow() override;
+    int sync() override;
+
+private:
+    int fdsync();
 };
 
 fdbuf::fdbuf(int fd)
@@ -220,7 +223,10 @@ fdbuf::fdbuf(int fd)
 }
 
 fdbuf::~fdbuf() {
-    this->close();
+    if (!(this->fd_ < 0)) {
+        this->fdsync();
+        ::close(this->fd_);
+    }
 }
 
 void fdbuf::open(int fd) {
@@ -248,6 +254,10 @@ int fdbuf::overflow(int c) {
 }
 
 int fdbuf::sync() {
+    return fdsync();
+}
+
+int fdbuf::fdsync() {
     if (this->pbase() != this->pptr()) {
         std::streamsize size(this->pptr() - this->pbase());
         std::streamsize done(::write(this->fd_, this->outbuf_, size));