From: Bo Persson on
Igor Tandetnik wrote:
> Jack wrote:
>> I hv deleted the "delete binfile" line,but still
>> buffer overrun
>
> Because you are still writing past the end of allocated buffer.
>
> std::vector< BYTE > v( size.QuadPart+0x1e0-4 );
> memset (binfile, 0, size.QuadPart+0x1e4-4);
>
> Note 0x1e0 in the first line, 0x1e4 in the second.

This is one very good reason for using named constants and no magic
numbers!

Also, the vector is already initialized to zero by the first line, so
there is no need whatsoever for the memset.


Bo Persson


From: Barry Schwarz on
On Wed, 16 Dec 2009 20:33:03 +0800, "Jack" <jl(a)knight.com> wrote:

snip

>
> std::vector< BYTE > v( size.QuadPart+0x1e0-4 );
>
> BYTE * binfile = &v[0];
>
>
> //PBYTE binfile = new BYTE[size.QuadPart+0x1e0-4]; // maybe get the file
>size 1st
> memset (binfile, 0, size.QuadPart+0x1e4-4);

You are overrunning the memory pointed to by binfile by 4 bytes.

> //binfile.clear();
> memcpy (binfile, template_bin, 0x1e0);
> //binfile.push_back(template_bin);//, 0x1e0);
> binfile += 0x1e0;
>
snip

>if (binfile) {
>
> delete binfile;

You commented out the dynamic allocation so this makes no sense.

> binfile = NULL;
>
> }
>
>
> return S_OK;
>
>
>}
>
>
>

--
Remove del for email
From: Jack on
Update:

// No memory leak after comment operators removed
/* hr = D3DXLoadMeshHierarchyFromXInMemory((LPCVOID) pBin, j,
D3DXMESH_MANAGED, m_pDevice, &Alloc,
NULL, (LPD3DXFRAME*)&m_pFrameRoot, &m_pAnimController);*/

I worked hard to remove the heap corruption problem,
and now it's gone, but new problem arises,
When I comment out the above code,
there is no memory leaks, it suffers from memory leak
when this Direct3D function call is removed.

Detected memory leaks!
Dumping objects ->
{2034} normal block at 0x0213C5B8, 4 bytes long.
Data: < > 00 00 00 00
{2025} normal block at 0x0213BFD8, 4 bytes long.
Data: < > 00 00 00 00
{2016} normal block at 0x0213B9F8, 4 bytes long.
Data: < > 00 00 00 00
{2007} normal block at 0x0213B088, 4 bytes long.
Data: < > 00 00 00 00
{1998} normal block at 0x0213A760, 4 bytes long.
Data: < > 00 00 00 00
{1989} normal block at 0x02139DC0, 4 bytes long.
Data: < > 00 00 00 00
{1978} normal block at 0x02139680, 4 bytes long.
Data: < > 00 00 00 00
{1969} normal block at 0x021390A0, 4 bytes long.
Data: < > 00 00 00 00
......
More and more


Thanks
Jack



From: Jack on

> // No memory leak after comment operators removed
> /* hr = D3DXLoadMeshHierarchyFromXInMemory((LPCVOID) pBin, j,
> D3DXMESH_MANAGED, m_pDevice, &Alloc,
> NULL, (LPD3DXFRAME*)&m_pFrameRoot, &m_pAnimController);*/
>
> I worked hard to remove the heap corruption problem,
> and now it's gone, but new problem arises,
> When I comment out the above code,
> there is no memory leaks, it suffers from memory leak
> when this Direct3D function call is removed.

or with the function call.


>
> Detected memory leaks!
> Dumping objects ->
> {2034} normal block at 0x0213C5B8, 4 bytes long.
> Data: < > 00 00 00 00
> {2025} normal block at 0x0213BFD8, 4 bytes long.
> Data: < > 00 00 00 00
> {2016} normal block at 0x0213B9F8, 4 bytes long.
> Data: < > 00 00 00 00
> {2007} normal block at 0x0213B088, 4 bytes long.
> Data: < > 00 00 00 00
> {1998} normal block at 0x0213A760, 4 bytes long.
> Data: < > 00 00 00 00
> {1989} normal block at 0x02139DC0, 4 bytes long.
> Data: < > 00 00 00 00
> {1978} normal block at 0x02139680, 4 bytes long.
> Data: < > 00 00 00 00
> {1969} normal block at 0x021390A0, 4 bytes long.
> Data: < > 00 00 00 00
> .....
> More and more
>
>
> Thanks
> Jack
>
>
>


First  |  Prev  | 
Pages: 1 2 3 4 5 6
Prev: Function vs Method
Next: C-type casting