As stated, I'm getting "Invalid address specified to RtlValidateHeap" when deleting a pointer allocated with new. I've never seen this error before, and it occurs in main
.
Main.ccp:
#include <iostream>
#include "ConsolePrinter.h"
int main(int argc, char* argv[]) {
std::cout << "Test" << std::endl;
ObjectPrinter* op1 = new ConsolePrinter('V');
op1->printObject();
delete op1;
}
ConsolePrinter
is derived from ObjectPrinter
. Both are custom classes
ObjectPrinter.h:
#ifndef OBJECTPRINTER_H
#define OBJECTPRINTER_H
#include <typeinfo>
class ObjectPrinter {
public:
virtual bool compatible(const ObjectPrinter* objprtr) const = 0;
virtual void printObject() = 0;
virtual const std::type_info& getType() const = 0;
};
#endif
ConsolePrinter.h:
#ifndef CONSOLEPRINTER_H
#define CONSOLEPRINTER_H
#include "ObjectPrinter.h"
class ConsolePrinter : public virtual ObjectPrinter {
public:
ConsolePrinter();
ConsolePrinter(unsigned char c);
bool compatible(const ObjectPrinter* objprtr) const;
virtual void printObject();
protected:
const bool compatibilityMode;
virtual const std::type_info& getType() const;
private:
const unsigned char repr;
};
#endif
Before delete op1;
:
- The address of
op1
is0x00E1BF7C
. - Within the heap,
op1
is instance<0x00E1BF50>
(according to Visual Studio's HEAP snapshot).
When delete op1;
is executed, the error given is Invalid address specified to RtlValidateHeap( 00E10000, 00E1BF5C )
.
If someone can explain why this is happening, I would be very appreciated.