P
PLS
This problem is entirely in Microsoft's VS2005 C++ headers, so I'm
hoping someone has hit it before and knows the fix.
I am convertied a medium size (400k lines) C++ program over to VS2005
native C++, rewriting it's COM stuff to ATL. I have crtdbg.h in the
global include file and have _CRT_MAP_ALLOC turned on at the project
level.
I'm getting a crash at line 707 in the function
_com_ptr_t::CreateInstance in file comip.h. The crash was an assertion
failure caused by a memory allocation problem.
I finally had to look at the disassembly to see what the difficulty was.
There are two line from this function that cause the problem:
clsidStringW = static_cast<LPWSTR>(_malloca(destSize * sizeof(WCHAR)));
and
_freea(clsidStringW);
According to the disassembly, the first is converted to
clsidStringW = static_castM<LPWSTR>(_malloc_dbg(...));
and the second is compiled to
_freea(clsidStringW);
and _freea fails trying to free a memory area that wasn't allocated with
_malloca.
Here is the function after preprocessing:
HRESULT CreateInstance(LPCSTR clsidStringA, IUnknown* pOuter = 0,
DWORD dwClsContext = (CLSCTX_INPROC_SERVER| CLSCTX_INPROC_HANDLER|
CLSCTX_LOCAL_SERVER| CLSCTX_REMOTE_SERVER)) throw()
{
if (clsidStringA == 0) {
return ((HRESULT)0x80070057L);
}
int size = lstrlenA(clsidStringA) + 1;
int destSize = MultiByteToWideChar(0, 0, clsidStringA, size, 0,
0);
if (destSize == 0) {
return ((HRESULT)(GetLastError()) <= 0 ? ((HRESULT)
(GetLastError())) : ((HRESULT) (((GetLastError()) & 0x0000FFFF) | (7 <<
16) | 0x80000000)));
}
LPWSTR clsidStringW;
clsidStringW = static_cast<LPWSTR>(_malloc_dbg(destSize * sizeof
(WCHAR), 1, "c:\\program files\\microsoft visual studio 8\\vc\\include
\\comip.h", 695));
if (clsidStringW == 0) {
return ((HRESULT)0x8007000EL);
}
if (MultiByteToWideChar(0, 0, clsidStringA, size, clsidStringW,
destSize) == 0) {
_freea(clsidStringW);
return ((HRESULT)(GetLastError()) <= 0 ? ((HRESULT)
(GetLastError())) : ((HRESULT) (((GetLastError()) & 0x0000FFFF) | (7 <<
16) | 0x80000000)));
}
HRESULT hr=CreateInstance(clsidStringW, pOuter, dwClsContext);
_freea(clsidStringW);
return hr;
}
With a quick look at the crtdbg.h, I looks like _freea() should be
converted to _free_dbg, which would work fine.
Any ideas how to fix this?
It's probably useless to file a bug report on this, given that ATL is no
longer supported.
++PLS
hoping someone has hit it before and knows the fix.
I am convertied a medium size (400k lines) C++ program over to VS2005
native C++, rewriting it's COM stuff to ATL. I have crtdbg.h in the
global include file and have _CRT_MAP_ALLOC turned on at the project
level.
I'm getting a crash at line 707 in the function
_com_ptr_t::CreateInstance in file comip.h. The crash was an assertion
failure caused by a memory allocation problem.
I finally had to look at the disassembly to see what the difficulty was.
There are two line from this function that cause the problem:
clsidStringW = static_cast<LPWSTR>(_malloca(destSize * sizeof(WCHAR)));
and
_freea(clsidStringW);
According to the disassembly, the first is converted to
clsidStringW = static_castM<LPWSTR>(_malloc_dbg(...));
and the second is compiled to
_freea(clsidStringW);
and _freea fails trying to free a memory area that wasn't allocated with
_malloca.
Here is the function after preprocessing:
HRESULT CreateInstance(LPCSTR clsidStringA, IUnknown* pOuter = 0,
DWORD dwClsContext = (CLSCTX_INPROC_SERVER| CLSCTX_INPROC_HANDLER|
CLSCTX_LOCAL_SERVER| CLSCTX_REMOTE_SERVER)) throw()
{
if (clsidStringA == 0) {
return ((HRESULT)0x80070057L);
}
int size = lstrlenA(clsidStringA) + 1;
int destSize = MultiByteToWideChar(0, 0, clsidStringA, size, 0,
0);
if (destSize == 0) {
return ((HRESULT)(GetLastError()) <= 0 ? ((HRESULT)
(GetLastError())) : ((HRESULT) (((GetLastError()) & 0x0000FFFF) | (7 <<
16) | 0x80000000)));
}
LPWSTR clsidStringW;
clsidStringW = static_cast<LPWSTR>(_malloc_dbg(destSize * sizeof
(WCHAR), 1, "c:\\program files\\microsoft visual studio 8\\vc\\include
\\comip.h", 695));
if (clsidStringW == 0) {
return ((HRESULT)0x8007000EL);
}
if (MultiByteToWideChar(0, 0, clsidStringA, size, clsidStringW,
destSize) == 0) {
_freea(clsidStringW);
return ((HRESULT)(GetLastError()) <= 0 ? ((HRESULT)
(GetLastError())) : ((HRESULT) (((GetLastError()) & 0x0000FFFF) | (7 <<
16) | 0x80000000)));
}
HRESULT hr=CreateInstance(clsidStringW, pOuter, dwClsContext);
_freea(clsidStringW);
return hr;
}
With a quick look at the crtdbg.h, I looks like _freea() should be
converted to _free_dbg, which would work fine.
Any ideas how to fix this?
It's probably useless to file a bug report on this, given that ATL is no
longer supported.
++PLS