CGE: Fixed more free/delete[] mismatches identified by Valgrind

This commit is contained in:
Paul Gilbert 2011-07-10 17:56:29 +10:00
parent 1870f09d31
commit 88c7b25e5b
4 changed files with 21 additions and 9 deletions

View File

@ -151,7 +151,7 @@ Bitmap::~Bitmap() {
delete[](uint8 *) _v;
break;
case FAR_MEM :
free(_v);
delete[] _v;
default:
warning("Unhandled MemType in Bitmap destructor");
break;
@ -206,7 +206,7 @@ BMP_PTR Bitmap::code() {
delete[](uint8 *) _v;
break;
case FAR_MEM :
free(_v);
delete[] _v;
break;
default:
warning("Unhandled MemType in Bitmap::Code()");
@ -294,7 +294,7 @@ BMP_PTR Bitmap::code() {
break;
uint16 sizV = (uint16)(im - 2 - _v);
_v = farnew(uint8, sizV + _h * sizeof(*_b));
_v = new uint8[sizV + _h * sizeof(*_b)];
if (!_v)
error("No core");
@ -436,7 +436,7 @@ bool Bitmap::loadVBM(XFile *f) {
f->seek(f->mark() + PAL_SIZ);
}
}
if ((_v = farnew(uint8, n)) == NULL)
if ((_v = new uint8[n]) == NULL)
return false;
if (f->_error == 0)

View File

@ -136,6 +136,8 @@ CGEEngine::~CGEEngine() {
delete _console;
// Delete engine objects
delete _vga;
delete _sys;
delete _sprite;
delete _miniCave;
delete _shadow;
@ -153,8 +155,6 @@ CGEEngine::~CGEEngine() {
delete _snail;
delete _snail_;
delete _hero;
delete _vga;
delete _sys;
}
Common::Error CGEEngine::run() {

View File

@ -154,7 +154,7 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0)
_buttons = 0;
_busy = NULL;
_active = false;
_flags._kill = true;
_flags._kill = false;
setSeq(ms);
BMP_PTR *MC = new BMP_PTR[3];

View File

@ -356,12 +356,14 @@ Sprite::Sprite(CGEEngine *vm, BMP_PTR *shpP)
_seqPtr = 0;
_shpCnt = 0;
_prev = _next = NULL;
static int ctr = 1;
debug("create %d %x", ctr++, this);
setShapeList(shpP);
}
Sprite::~Sprite() {
debug("destroy %x", this);
if (_sprite == this)
_sprite = NULL;
contract();
@ -775,7 +777,7 @@ BMP_PTR Sprite::ghost() {
error("No core");
bmp->_w = e->_b1->_w;
bmp->_h = e->_b1->_h;
if ((bmp->_b = farnew(HideDesc, bmp->_h)) == NULL)
if ((bmp->_b = new HideDesc[bmp->_h]) == NULL)
error("No Core");
bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h);
// TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment
@ -903,8 +905,18 @@ void Queue::insert(Sprite *spr) {
spr->contract();
}
template<typename T>
inline bool contains(const Common::List<T> &l, const T &v) {
return (Common::find(l.begin(), l.end(), v) != l.end());
}
Common::List<Sprite *> l;
Sprite *Queue::remove(Sprite *spr) {
if (contains(l, spr)) {
debug("N");
}
l.push_back(spr);
if (spr == _head)
_head = spr->_next;
if (spr == _tail)