Ask a Question

Do not see fake memory leak in a DLL

SOLVED
fred_temento
Occasional Contributor

Do not see fake memory leak in a DLL

Hello,

 

I am new to AQtime.

 

In order to understand how AQtime show memory leak (that i can understand) I decide to create a fake memory leak in a DLL of my exe : just a malloc(10) without free in a ctor of a call being instanciated ton of time.

 

When I quit my application... a ton of memory leak appears (not my code!) but not mine !

 

Furthermore, I did not find tuto or sample for pure C++ (not managed) memory profiling.

So I peak information on some tuto talking about delphi or C++ .net...

 

I did try with AQtime standalone and integrated in Visual Studio 2013.

 

can you help on why my fake memory leak is not find ?

 

 

9 REPLIES 9
AlexKaras
Community Hero

Hi,

 

> fake memory leak in a DLL of my exe [...]

Have you added this dll to the list of project modules to be profiled?

Can you attach here your AQtime project (and .exe and .dll) ?

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
fred_temento
Occasional Contributor

Hi Alex,

 

thanks for your feed back.

 

>Have you added this dll to the list of project modules to be profiled?

of course ! 

I did it manually on my standalone AQtime project and it was done automatically by the intergrated version.

So, I think it's done !

 

>Can you attach here your AQtime project (and .exe and .dll) ?

I zip it... I suppose that an AQTime project is only made of the *.aqt file !

For information the fake memory leak is in the TSFC.dll module, TSString.cpp file, CTSString class default ctor which is called many times (I check with a breakpoint in debug mode)

 

Here is the code:

CTSString::CTSString ()
{
m_Size = 0;
m_BufferSize = STARTING_BUFFER_SIZE;
m_pBuffer = NULL;
SetNeededBufferSize (false);
m_pBuffer[0] = 0;

char * p = (char *)malloc(10); // p is never free to check for ML

}

 

You will see, with Windbg, that the MSVCRT embeded memory check, see my fake memory leak (but without reporting line information)

 

Detected memory leaks!
Dumping objects ->
{650} normal block at 0x006FE5D8, 10 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD

 

You'll find attached a 7Z file containing my AQTime (standalone version) projet and minimal subset version of my exe with it's DLL as requested.

 

(I cannot use ZIP since the ZIP file is more than your limit of 20,000,000 bytes !)

 

Running Diatem.exe stops at checking licence time but it's not an issue since the CTSString default ctor is called a lot of time before this. So it's enought for test prupose.

 

 

Thanks for your help.

 

 

 

 

 

 

Hi,

 

Thank you for the project.

This is what I did after I unpacked the archive and opened it in AQTime:

a) As AQTime stores full path to the profiled modules in the project and provide no means to batch 'rebase' them, I had to remove all modules from the project and add them a-new and marked DiaTem.exe as the Active module;

b) Initial launch of DiaTem.exe failed for me because of absence of the required mfc120d.dll, msvcp120d.dll and msvcr120d.dll DLLs. DiaTem.exe started successfully after I downloaded the mentioned DLLs (mine box does not have VC2013 debug redistributables);

c) I noted, that none of the binaries in the archive contains debug information;

d) In the Setup | Classes To Profile panel I created a new area of including type, added TSFC.dll to it and made this area the only selected one;

e) Started profiling.

 

I tried both: to press Get Results button in AQTime while the License window is on screen and to wait for the final results after the window was closed and the DiaTem.exe exited.

Initially, indeed, I got an empty results on the Report panel. But after I deactivated the View Project Classes Only filter (a button in the middle of the toolbar just above the results I saw a line with the leak of C++ Native Memory type.

After I double-clicked this line to select it (and pressed the View Allocation Paths In Call Tree button) I was able to see a couple of reported leaks of 10 bytes each in the Call Graph and Call Tree panels. No module name / line number info was provided because (I think) no debug information was provided.

I was able to see every separate leaked allocation after I selected Objects node in the results tree.

I was not able to check if you has got the same results because you did not include the folder with report data (named diatem3.6_Results) in the archive.

 

Attached is my project file with the results and a screenshot of profiling results.

 

Does the above help?

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
fred_temento
Occasional Contributor

Thanks for your reply.

What you say is realy confusing me !

 

First you say that you need to download the DEBUG redistributable of VS2013 (sorry for not shipped it; I thought you had them installed since Memory profiling DO needs debug builds) So this mean that my binaries do need debug version of MFC and CRT libraries. Right ?

 

and after you say that ALL my binaries has NO DEBUG INFO ! 

 

I can say that VS2013 is able to debug all my binaries ! so I think all my binaries is build with debug info.

I just verify that the size of TSFC.DLL is really different between debug and release build : 283K for debug version and 57K for release version. (and I double check that this is the 283K version that I sent you !)

 

Do you know a way to guess if a DLL is a debug or release build ? 

 

Anyway, there are many compiler option to build a debug version. And unfortunatly I did not find the settings to put on my vcxproh VS2013 project to suit the AQtime needs. I only find delphy ones... that do not help me.

 

I think the issue is there : What are the debug compiler flag/option to use in Visual Studio 2013, to be compliant with AQTime ?

 

I did not know about the diatem3.6_Results directory ! but I can't send it because it is too large :

"

  • The attachment diatem3.6_Results.7z is too large and has been removed. The maximum file size is: 20,000,000 bytes."

 

Thanks a lot for your feedback.

Hi,

 

> [...] since Memory profiling DO needs debug builds

Well, I am not a C/C++ expert, but this is my understanding. First: debug code and debug info are different things. Debug code contains less optimizations then release code and may contain additional code (that, for example, can verify if allocated memory block was overwritten or not). Debug information is just a map that describes where in the memory (executable image) this or that variable is located and what is its name and makes it possible to establish a correspondence between binary code and source text.

Considering the above, debug info can exist and be provided for both, debug and release code.

So, your code was compiled as debug one (and thus references debug versions of runtime dlls) but did not have associated debug info.

 

> Do you know a way to guess if a DLL is a debug or release build ?

If I remember correctly, there is a corresponding flag in the executable header, but I think that it is up to the compiler whether to set it or not and what code to consider to be a debug one.

 

> What are the debug compiler flag/option to use in Visual Studio 2013, to be compliant with AQTime ?

https://support.smartbear.com/viewarticle/43036/ and related articles should provide the needed info.

 

P.S. Documentation by SmartBear is one of the best ones that I ever saw, so I really recommend to spend some time to read it in detail.

 

Does the above resolve your confusions?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
fred_temento
Occasional Contributor

Thanks for your help.

 

First, I wanted to tell you that I thought you were a support staff guy from Smartbear ! I just realized that I was wrong ! So sorry for asking you to solve my issues ! I will surely redirect my message to the support staff since there is something strange in the beahvior of AQTime with my code.

 

Thanks for the link to setup VS2013 (I did not find it before). But I agree with you that the SmartBear documentation is one of the best of the world !

 

So regarding the fact that you are not a c++ expert : what you say about debug/release build is true and I know that (I am very familiar with c++ maybe an expert !). Except that debug code contains "NO" optimization at all. So I don't understand why the article you sent me tells to use a Release build to add debug info in it since it will be still optimized (unless you disable it by /Od)

 

>So, your code was compiled as debug one (...) but did not have associated debug info.

Since all my project can be debugged with VS2013 and all settings are set on all modules... I don't know how it's possible

Anyway I checked once again that all settings are compliant with AQTime. Except the "Enable Function-Level Linking option" it was OK. Unfortunatly this option makes my code no more link. I am investigating.

 

 

So I can understand that because there are explaining how to profil for performance.

Indeed profiling for performance should included compiler optimization but not profiling for memory. AQtime is the only soft I use for memory leak hunting that behave like this regarding memory management. I never had any issue with boundchecker or purify to hunt for memory leak with my debug builds... 

 

Anyway thanks to the article you sent me I think that I have a possible solution to solve my issue (what you call Debug build with debug info). My build sperates bianries from pdb files. So maybe AQTime needs PDB files to consider it is debug build... 

 

I will tell you (and the community) if it solves my issue when I will succeed to solve the Enable Function-Level Linking issue.

 

Thanks for your help.

 

Hi,

 

> So sorry for asking you to solve my issues !

Absolutely not a problem. Guys at Smartbear forums are pretty helpful and for me personally your request was a good stimulus to refresh my AQtime's knowledge. 🙂 You may create a Support ticket via the https://support.smartbear.com/message/?prod=AQtime form. Also there is an online troubleshooter at https://support.smartbear.com/about-troubleshooter/, but it is irrelevant for your case.

 

> So maybe AQTime needs PDB files to consider it is debug build

Yes, absolutely. I don't know exact implementation, but from the end-user point of view, when you add a module to AQtime's project, AQtime looks for the debug information to be either built-in into the file (e.g. like it can be done for Delphi applications) or to be in the .pdb filelocated in the same folder as the processed file (or in the known folder - https://support.smartbear.com/viewarticle/43347/). If the .pdb file is not found, AQtime considers module as the one without debug info (that is, obviously, correct).

 

> So I don't understand why the article you sent me tells to use a Release build to add debug info in it since it will be still optimized 

Several notes:

a) Yes, I agree that optimized Release build should be used when profiling for performance. Assuming that optimizations done for Release do not introduce new memory leaks when compared to Debug and that extra debug code in the Debug build does not contained leaks either, either Debug or Release builds can be used for the memory leaks profiling;

b) As files with debug info are the supplimentary files for the binaries compiled as Release or Debug, they (debug info files) can be created for both Debug and Release builds;

c) Depending on how well optimizations done for Release can be assosiated with the source code, you may get more or less clear results when profiling on the line level. But I think that on the routines level (that should be done initially as it less loads test system and is more easy for analysis) profiling results should be quite clear. 

 

P.S. https://support.smartbear.com/viewarticle/43136/ section of documentation might appear to be helpful (unless you already have familirized yourself with it).

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
fred_temento
Occasional Contributor

Hi Alex,

 

Thanks for all your comments.

 

I did follow the recommandation for building native  c++ projects : I had to change my 52 projects of my application since an option was disabled and AQtime needs it (Function Level Linking). This was a great think since it generates a lot of link errors that were real errors (indeed I don't undestand how the code was working before !). I must say that my application was last converted from VC6 to VS2013 ! So the project file settings were automatically translated from VC6 to VS2013 (+ some manual action)... and those both compilers are REALLY different ! So switch FLL ON was a good thing !

I also set all my project to use /Zi (since all my project can not use /ZI because of /SEshc settings)

I verified and setup the directory to use PDB files (indeed it was good, only vc120.pdb was missing)

I studied your screen shot (that was helpfull regarding the small button !) 

I verified the "Project Search Drectories" for source picking.

and I can see the same results as yours.

 

I don't understand why it is mandatory to create a "class level area" since, by definition, we don't know where are memory leaks ! but I created it and put the DLL into which I create a memory leak (malloc without free).

 

Finally I can see the same results as yours + source file and line number ! (see attached)

BUT still no source code can be viewed when double click on a Call tree CTSString line item....

(no more error message saying that there are no source code available or no debug info)

 

 

So, I must really thank you all the time you spent for me. I think there is something abnormal in my application solution that do not please AQTime. 

 

I will know try with a dummy "hello world" like native C++ MFC application build from scratch using the VS2013 wizard and see if the results a re more accurate.

 

and finally open a support ticket !

 

Once again, many thanks to you ! 

 

oops : last minute ! I just saw that the line number of leak is really innacurate since it do not point on the malloc but on the ctor opening brace... at line 42 (see attached)

 

very last minute !

 

Finally after trying on another mushc smaller app, reading more help, clicking everywhere..; I finally found what I am looking for days : 

 

The "Classes Data" view is not the better place to find leaking code but just if there are leak

The "Objects" view is better ! Associated with the Details view, Creation Call Stack pane, allow to double-click on a symbol and see the source code ...

BUT this must be used with the "View project class only" button DISABLED ! (so thanks for that !). So now I find my dummy leak (see attached).

 

My point of view is that having memory leak information is not a straight forward process !

To much information makes real information noisy. (I was thinking that purrify was too verbose... but AQTime is much more graphically noisy!).

Also the "Object Name" column that list "C++ native memory.xxxx" is not really helpful.

 

I think that a simplified unique view can be done in order to directly point on the memory leak.

 

 

Now I can refine my question:

- What is the aim of the magic button "View project class only" ?? 

It seems strange to disable it in order to see the leak of the class of my project! Is project meaning only the executable ??

why my DLL behing part of my project is not considered as included in my project ??

 

Anyway, I set this post as Answered. 

 

Thanks again Alex.

 

 

 

@fred_temento

Hi Fred,

 

It is good to hear that in general you was able to get what you was looking for and that recommendations from AQTime's documentation helped to improve your code.

 

> What is the aim of the magic button "View project class only" ??

According to the documentation (https://support.smartbear.com/viewarticle/54501/), this button filters "profiling results for those modules that are added to the Setup panel." Indeed, the leak occurs starting from the msvcr120d.dll and this dll was not included in the AQTime's project. (General AQTime's concept: profiling is done only for the stuff that is added to the Modules list and is included in some Area and is not blocked by some Action or Trigger (see help for more details about these entities).)

What I did: I switched to the PE Reader panel (set of panels in the lower part of AQTime's screen), expanded the node for tsfc.dll, right-clicked on the msvcr120d.dll node and selected Add Module to Project menu command. Then I did another profiling run and the leak was displayed in the Results regardless of the state of the View Project Classes Only button.

Hope, this will make AQTime's behavior more clear.

 

> I don't understand why it is mandatory to create a "class level area" [...]

Actually, this is not required and you can do a profiling run without any area added but with only All Project Modules by Classes option enabled (in the Classes to Profile pane of the Setup panel). Areas in AQTime are just means to reduce the volume of the collected profiling information in order to lower the load on the test system. https://support.smartbear.com/viewarticle/43495/ topic of the https://support.smartbear.com/viewarticle/42966/ section should explain this better.

 

> [...] The "Objects" view is better !

https://support.smartbear.com/viewarticle/43467/ and https://support.smartbear.com/viewarticle/43019/ help topics (of https://support.smartbear.com/viewarticle/42965/ section) should explain the difference between those views and also explain why you did not see source information for the Classes Data results view.

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
cancel
Showing results for 
Search instead for 
Did you mean: