Analyzers
Support for Analyzers (Intel VTune™ Profiler, Intel Advisor, Intel Inspector)
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
4679 Discussions

Mismatched allocation/deallocation

Nils_O_
Beginner
128 Views
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

[bash]
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 != NULL)
            delete m_list; //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;
}
[/bash]

0 Kudos
0 Replies
Reply