157. Polymorphism-ii

Question.1

A critical firmware bug:

class IDriver {
public:
   virtual void init() = 0;
   // ~IDriver() -- NOT virtual!
};
class UART : public IDriver {
   uint8_t* buf;
public:
   UART() : buf(new uint8_t[64]) {}
   ~UART() { delete[] buf; }
   void init() override {}
};

IDriver* d = new UART();
delete d;

What is the consequence?

Need Help? Refer to the Quick Guide below

Select Answer