Archive for category Uncategorized

debugging MSVC++ CRTL memory leaks

It seems like none of the docs on this subject are quite complete.

One of the most missed issues is that there can be multiple heaps in a single process. DLLs that use the CRTL, for example, can get a module-local heap. Each heap will get a separate run of the dump activity, so the allocation number shown in the dump report is local to that heap. You might not break in the right place if you don’t set up the allocation break number in the right module.

When I see the “Detected memory leaks!” message, I put a breakpoint in the _CrtDumpMemoryLeaks() function. This function is in dbgheap.c, which installs to C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src\dbgheap.c in Visual C++ 2013. It’s the same module that implements _CrtSetDbgFlag() and _CrtSetBreakAlloc(), so stepping into those functions can help open the file.

Breaking on that function’s output of the leaked blocks will reveal the module that’s actually making the call; just look at the module name information in the stack when the breakpoint is hit.

After finding the right module, adding these two lines of code to the application’s InitInstance() method should get the allocator to break on the appropriate allocation number:


The break call might be placed in main() or in DllLoadLibrary(); whatever is the earliest available point. Static constructors run before these method are called, so it’s conceivable that another static constructor needs to be written to get the all in place early enough.

Some sources show multiple calls to _CrtSetBreakAlloc() implying that the library can check for multiple break numbers — but it can’t.

Asking about Questions

Over at The Ladders, career coach Lee E. Miller advises about a question lots of interviewees get: Tell me about yourself.

Mr Miller is right about one thing: this question shouldn’t take an interviewee by surprise. An interviewee should be poised and confident, and shouldn’t hesitate to describe themselves or their experiences. After all, providing compelling descriptions about yourself — compelling enough to decide that you’re a hire — is what interviewing is all about for the candidate.

But I think he blows it in one critical regard. He says that the wrong answer is to ask “what would you like to know?” and explains that such a response indicates the candidate hasn’t prepared.

I couldn’t disagree more. A candidate who asks such a question is showing respect for the interviwer’s time. He can assume he knows what the interviewer wants, but wouldn’t it be better to make sure his information and conclusions are correct? If he can confirm that he’s going to attack the right targets, then he’s in much better shape than someone who’s got the wrong idea and starts off in the wrong direction.

Mr Miller asserts that a candidate asking this question isn’t prepared, and wouldn’t be prepared on the job. That seems like an illogical conclusion; one’s instantaneous performance for a single, out-of-domain question probably doesn’t forecast their performance for their at-work tasks. Further, if we supposed Mr Miller’s  brand of conclusion were correct, we could also assume a candidate who doesn’t ask this question is someone who would assume they were right and commit to a direction which they haven’t previously verified. How many experienced managers have worked with an employee — a new hire, in particular — who went off in a certain direction without verifying that direction was in the best interests of the company and all the stakeholders in the matters touched by that work?

After all, that’s what Mr Miller is insisting the candidate should do.

Where can I get good news?

I turned on CNN looking for coverage of the Tohoku earthquake. I’m not sure I’m allowed to watch CNN anymore.

The first story I saw was about a YouTube video made by a New York senator that “teaches parents to spy on their kids”. The idea is that the parents learn how kids hide thing and where to look for drugs, weapons, or other dangerous items. I’m not sure this is news, but it seems okay if CNN spends a bit of time on human interest stories.

Thing was, though, CNN made this the “Your Views Question of the Day”. They solicited input on the Internet, then read comments users made on the air. Who care what Ricky from Indiana thinks about this story? Why is spending 90 seconds on reading reader comments, without analyzing them, at all useful?

Coverage moved to Hawaii, where some effects of the tsunami were felt. At 20 seconds, the segment was incredibly short and conveyed zero information. Why not show a map of Hawaii, drawing lines on the coast where green, yellow, and red indicate the severity of the damage? No damage reported? No line, then.

The description of the damage was hopelessly vague and un-insightful. Why dumb down such a simple report so severely?

The next story was about Rhode Island requiring high school students “to score at least partially proficient” on a standardized test in order to graduate. The coverage involved an interview with a representative with the ACLU, an organization with amiable goals but — as far as I can tell — zero influence or experience in the area of education or child development. What about the other side of the coin? Why not interview students who are bored because their classes cover material at the pace of the slowest student? Why not interview colleges or employers who are tired of teaching recent graduates things that they should have learned earlier in school?

The shallow depth of coverage, one-sided reporting, and shameless self-promotion leave me cold. Is there a news outlet that is acceptable?

Test Post #4

What else could be wrong?

Understanding RSA Chiphers

I found a great article on understanding RSA public key ciphers. There’s just enough background information and good description of the mechanics.