Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
4995 Discussions

Failure to find simple memory leaks

jon611
Beginner
291 Views

I'm evaluating Intel Inspector for our project at my work and it is failing to find simple memory leaks I've added as a test.

For example, I added the following code to our project and it is not reported on any run level of memory analysis in Intel Inspector.

char* MyString = new char[1111];
LOG_EVENT("LEAKING MEMORY HERE!")

However, if I put this in a dummy project, Intel Inspector finds the leak properly. The only thing I can think is that our project has slightly different build settings, namely the Code Generation/Runtime Library is set to /MTd as opposed to /MDd. However, even in my dummy project setting this does not have any effect on Intel Inspector's ability to find such blatant errors. Is there anything else I should be looking for in my project that would keep Intel Inspectorfrom finding errors?

0 Kudos
3 Replies
David_A_Intel1
Employee
291 Views
So, there are a couple of things that could be happening. Where did you add this code in your project? Did you add it to main()? What we have seen is that code related to exception handling will store values from the stack in global memory. If this global memory now contains the value equal to the pointer to that returned block, we will think the allocation is reachable. If an application exits with reachable allocated memory (e.g., a ptr to the memory), we assume the developer purposely did not free the memory, since all resources are freed upon exit by the OS.

It seems that this is most likely to happen if the block is allocated early in the process, i.e., close to the start of main(). If you try adding said code to some sub-functions, you may find the leaks are more reliable reported.

Something else that might work for this case of leak detection is to use something like GlobalAlloc() or LocalAlloc().
0 Kudos
jon611
Beginner
291 Views

The intentional memory leak code I added was in the constructor of a class that is created a single time on the run of my program.

After my post yesterday, I changed my project to do code generation via /MDd switch. On the first run of Intel Inspector it found all memory errors I had added at the "Detect Leaks" memory analysis level. I then removed most of the errors I had intentionally added and re-ran Intel Inspector on the "Detect Leaks" memory analysis level and it found 0 errors, missing 3 errors I had intentionally added. I then ran at the "Detect Memory Problems" level with Intel Inspector and it found all memory errors I had injected. Based on the options and their descriptions this seems odd to me as I thought the leaks would be caught on the first level as they previously were found when I had more errors.

Anything I can look for to explain the inconsistency of finding my memory errors?

0 Kudos
David_A_Intel1
Employee
291 Views
I'm sorry but, at this point, the best, next step is for you to submit an issue at Intel Premier Support and attach some code that we can use to investigate this issue. Without some concrete examples, it is difficult and potentially misleading to speculate what is happening.
0 Kudos
Reply