Wednesday, September 11, 2019

Geek Squad's WebRoot Utility is Pretty Smart

It says that Thunderbird has a memory leak, and dllhost.exe has a handle leak.

The memory leak may well explain why things get worse over time.

If you aren't a geek, let me explain a memory leak.  A C program allocates temporary blocks of RAM for particular tasks from an area called "the heap."  When it is done with that block, it returns it to the heap for reuse at a later time.  I take that back; it is supposed to return it to the heap.  If  not, over time, the available memory in the heap gets smaller and smaller.  Your heap has a leak.

Back when I first started writing in C, these leaks were so annoying that I overrode the default malloc and free functions, which as the names suggest, allocate memory and then return it to the heap.  My versions would record every block allocated when malloc was called and then remove it from the list when that same block was freed.  When the program exited, you had a list of blocks that had not been freed.  By recording also where these calls happened, it was possible to go back and find the badly behaved code, 

An additional problem was allocating say, 50 bytes of RAM from the heap, and using more than 50 bytes at that location.  Because of how C organized the heap, you could scramble things pretty badly.  My solution was the have my version of malloc allocate 54 bytes, and put some distinctive pattern in the last four bytes.  When my free was called, it would verify that the pattern was still there.  If it was, I could then track down who had gone off the far end of the memory block.

I think this is now mostly paleosoftware engineering now.

No comments:

Post a Comment