Re: Why a Memory Leak Here:
On Jan 19, 9:42 pm, achalk <andy.ch...@gmail.com> wrote:
1) EkkoBackupFileType is defined as:
struct EkkoBackupFileType
{
std::wstring ext;
std::wstring bkp;
int type;
}
The std::wstring type stores the controlled string in a dynamically
allocated block of memory in order to be able to handle arbitrary
length strings.
This is most likely the cause of the memory-leak report, but unless
there is a serious bug in MSVC, the report is a false-positive.
2) _crtBreakAlloc was set with:
#if defined(_DEBUG)
int nOldState = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
nOldState |= _CRTDBG_LEAK_CHECK_DF;
nOldState |= _CRTDBG_CHECK_ALWAYS_DF;
_CrtSetDbgFlag(nOldState);
This causes the memory-checker to run at program termination.
What this memory-checker does is it simply checks for any blocks that
are still allocated by the program and report those as "leaks".
In this case, the checker runs too early and finds some allocated
memory that will be released in the destructor of some static-lifetime
objects (the global array).
You will see that in this program, there will also be a leak reported
for the int object that p refers to:
#include <iostream>
#include <crtdbg.h>
int main()
{
int* p = new int;
if (_CrtDumpMemoryLeaks())
{
std::cout << "Leak detected\n";
}
delete p;
}
_CrtSetBreakAlloc(231);
#endif
where 231 was the first allocation number shown as 'leaked' in the
dump at the end of the program.
3) I posted here because I did not see why a global (non-dynamic)
memory allocation should show up as a leak. Martin B's suggestion
seems closest but I cannot find any copies of this array in the code.
4) So this is still a mystery;
Bart v Ingen Schenau
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]