It was allocated, it would be at address 0x00000000 if it wasn't. Heres some code though:
Code:
void ZeroPacket::Free()
{
if( m_Data ) delete [] m_Data;
}
That is the line I get the error on, m_Data is the Bad Ptr supposedly.
Code:
BOOL ZeroPacket::SetData(const pcap_pkthdr *header, const u_char* data)
{
if( !header || !data )
return FALSE;
m_header = *header;
m_Data = new u_char[m_header.len+1]; //// m_Data is allocated
memcpy(m_Data, data, m_header.len);
return TRUE;
}
The above is self-explanatory, it allocates m_Data and copy's a packet header to it.
Code:
BOOL ZeroPacketData::SetData(ZeroPacket* Data)
{
if( Data == NULL )
{
//! Do Error
return FALSE;
}
if( !Data->IsLoaded() )
{
//! Do Error
return FALSE;
}
m_Packets.push_back(*Data);
delete Data; // CALLS THE DECONSTRUCTOR, THUS CAUSING THE ERROR
return TRUE;
}
delete Data calls the deconstructor for ZeroPacket and then calls Free().
EDIT: While it is being allocated, somewhere along the line its either losing the data written at that location, or its being turned to garbage data. So would it be ok not to delete it? Would that lead to a memory leak?