Mismatched allocation/deallocation

Mismatched allocation/deallocation

Hello,

I am getting a mismatched allocation/deallocation error.
It's strange becamse it happens on new and delete lines. The
deallocation error is on the line that is commented //DEALLOCATION, and
the corresponding allocation error is on the comment //ALLOCATION. The
code that causes this problem is below. I've attached the inspector
results. Is this a legitimate error?

I suspect that it is
because the program crashes in the Free() function when the destructor
is called. However I'm pretty sure I'm doing the right thing.

m_list is a STL vector. I've also tried using a C++ array with the same results. Platform is VC 2008. I've tried compiling with Intel compiler and also with VC 2005 with the same crashing effect.

Thanks for any help.

Nils

ICAPHPG::~ICAPHPG()
{
    Free();
}

ICAPHPG::ICAPHPG()
{
}

bool ICAPHPG::Allocate(int count_in)
{
    //m_list.reserve(count_in);
    //m_list.resize(count_in);
    m_hpgCount = count_in;
    return true;
}

void ICAPHPG::Free()
{
    for (unsigned int i = 0; i < m_list.size(); i++)
    {
        if (m_list[i] != NULL)
            delete m_list[i]; //DEALLOCATE
    }
}

bool ICAPHPG::loadHPG(int idx, const char* path)
{
    if (idx < 0 || idx >= m_hpgCount)
        return false;

    hpgns::CircularHPG* h = new hpgns::CircularHPG((char*)path); //ALLOCATE
    if (h == NULL)
        return false;
    else if (h->GetError())
        return false;

	m_list.push_back(h);
	return true;
}

AllegatoDimensione
Download r007mi2.zip179.88 KB
1 contenuto / 0 nuovi
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione