Leo
Leo

Reputation: 1139

Dynamically instancing a class then deleting it right away?

I created my own class but when I try to instantiate it I run into a wall.

Here's my code:

m_interpolation = new Interpolation(m_mesureList, width, height, parent);
delete m_interpolation;

Which generates the error:

Heap block at 0B3E9E40 modified at 0B3E9E68 past requested size of 20

I don't see what I'm doing wrong...

For information here is the full definition of my class Interpolation.h and Interpolation.cpp if that's of any help.

Added a destructor but still didn't fix the problem.

Interpolation::~Interpolation()
{
    delete m_progress;
    m_progress = 0;
}

Upvotes: 2

Views: 131

Answers (2)

tmpearce
tmpearce

Reputation: 12693

In the ctor: Populating m_w: up to (m_N-1)

for (int i(0); i < m_N; ++i)
{
    m_pt.push_back(QPointF(mesureList[i]->getX(), mesureList[i]->getY()));
    m_w.push_back(mesureList[i]->getAngle());
}

Later: accessing m_w[m_N], beyond the end of the vector

for (i = m_N; i >= 0; --i)
{
    sum = m_w[i];
    for (j = i+1; j < m_N; j++) sum -= LU[i][j]*m_w[j];
    m_w[i] = sum / LU[i][i];
}

Upvotes: 4

Rafael Baptista
Rafael Baptista

Reputation: 11499

Something inside the constructor Interpolation::Interopolation() or the destructor Interpolation::~Interpolation() is writing beyond the size of the object.

Upvotes: 0

Related Questions