Link to home
Create AccountLog in
Avatar of yarlapati
yarlapati

asked on

GetLastError() message

Hi All,

I am trying to find the memory leak in my C++ application and I am using the GetLastError() method which is returning the following.

"The operation completed successfully." as the GetLastError() error message.

Not really sure what it means, but this is coming from my catch block.

Also, can someone suggest how to find the memory leaks and any suggested tools.

This program works fine in the dev environment and fails on the production.

Any ideas would be appreciated.

K.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
>>>> I am using the GetLastError() method

GetLastError returns the last error occured in the Windows API. Error code 0 "The operation completed successfully." means there was no error. If GetLastError would return an error code different from 0 it only would mean that one of the last (internal) calls of the Windows API failed. But the error was handled cause there was no exception.

In any case GetLastError cannot be used to detect memory leaks. Use the method jkr recommended above or check if for any 'new' there is a corresponding 'delete'.

Regards, Alex
   
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of yarlapati
yarlapati

ASKER

Thank you for the replies.

Alex,

"check if for any 'new' there is a corresponding 'delete'. " :

I made sure that all the Objects created were deleted after every record processing.

JkR,

I used the technique you menitioned above and I got nothing in the Prod environment. But in the Dev env.. I got the following lines..

{214438} normal block at 0x00CA1F58, 33 bytes long.
 Data: < 1965           > 00 31 39 36 35 00 CD CD CD CD CD CD CD CD CD CD
{214437} normal block at 0x00CA1EC0, 84 bytes long.
 Data: < Qh 9650708     > 8C 51 68 00 39 36 35 30 37 30 38 00 00 00 00 00
{214422} normal block at 0x00C9D4C8, 33 bytes long.
 Data: < 24             > 00 32 34 00 CD CD CD CD CD CD CD CD CD CD CD CD
{214420} normal block at 0x00CA1D20, 33 bytes long.
 Data: < 12             > 00 31 32 00 CD CD CD CD CD CD CD CD CD CD CD CD
{214415} normal block at 0x00CA7AE8, 33 bytes long.
 Data: < 1928           > 00 31 39 32 38 00 CD CD CD CD CD CD CD CD CD CD

And it doesn't seem to be of much help to me. Not sure if I am missing anything.

Can you please suggest what more needs to be done.

Regards,
K.
Yes, that's only displayed whe you run the app under a debugger. In a debug build, you should get the line number information also.
Alright.

When I run the app on my machine it runs fine with out any exception but when I run in different env( Prod), I get the memory problem and there is no way that I can run the debbuger on the other environment.

Any ideas?
Also, I just saw that I got the following lines when  ran in the debug mode on my machine..

Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\EntAPI.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\psapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\netapi32.dll', no matching symbolic information found.
Detected memory leaks!
Dumping objects ->
{44208931} normal block at 0x0498E3D8, 160 bytes long.
 Data: <<Tabdef,"-$,,.00> 3C 54 61 62 64 65 66 2C 22 2D 24 2C 2C 2E 30 30
{44208649} normal block at 0x12236E60, 160 bytes long.
 Data: <<Tabdef,"-$,,.00> 3C 54 61 62 64 65 66 2C 22 2D 24 2C 2C 2E 30 30
{44204859} normal block at 0x0498D630, 33 bytes long.
 Data: < 2000           > 00 32 30 30 30 00 CD CD CD CD CD CD CD CD CD CD
{44204858} normal block at 0x0498D700, 84 bytes long.
 Data: < Qh 0000000     > 8C 51 68 00 30 30 30 30 30 30 30 00 00 00 00 00
{44204857} normal block at 0x0498D5C8, 33 bytes long.
 Data: < 8              > 00 38 00 CD CD CD CD CD CD CD CD CD CD CD CD CD
{44204855} normal block at 0x0498D698, 33 bytes long.
 Data: < 3              > 00 33 00 CD CD CD CD CD CD CD CD CD CD CD CD CD
{44204850} normal block at 0x04995840, 33 bytes long.
 Data: < 2006           > 00 32 30 30 36 00 CD CD CD CD CD CD CD CD CD CD
{44204849} normal block at 0x0498D530, 84 bytes long.
 Data: < Qh 0060308     > 8C 51 68 00 30 30 36 30 33 30 38 00 00 00 00 00
{44204843} normal block at 0x0498CEA0, 33 bytes long.
 Data: < 2000           > 00 32 30 30 30 00 CD CD CD CD CD CD CD CD CD CD
{44204842} normal block at 0x0498D498, 84 bytes long.
 Data: < Qh 000000000000> 8C 51 68 00 30 30 30 30 30 30 30 30 30 30 30 30
{44204836} normal block at 0x0498D430, 33 bytes long.
 Data: < 2000           > 00 32 30 30 30 00 CD CD CD CD CD CD CD CD CD CD
{44204835} normal block at 0x0498CF08, 84 bytes long.
 Data: < Qh 0000000     > 8C 51 68 00 30 30 30 30 30 30 30 00 00 00 00 00
{44204817} normal block at 0x04994148, 33 bytes long.
 Data: < 2000           > 00 32 30 30 30 00 CD CD CD CD CD CD CD CD CD CD
{44204816} normal block at 0x0498CE08, 84 bytes long.

But I dont see any line numbers in them???
>>>> But I dont see any line numbers in them???

The leaks you posted were from modules where no C++ source code is available, e. g. from functions of the WINAPI that are written in C (or Assembler) or where the allocation is made by malloc rather than by new.

Look at the bottom of that list. Normally, there are a few lines where line numbers and source file names can be double-clicked. All other leaks were subsequent to these, e. g. because of class members.

Did you use MFC?

Regards, Alex
All,

Thank you very for your posts.

I found the memory leak using the above techniques and was able to correct it.

Also just wanted to paste the article which was also helpful in finding the memory leak.

http://www.codeproject.com/tools/visualleakdetector.asp

Regards,
K.