MrBayes icon indicating copy to clipboard operation
MrBayes copied to clipboard

Memory leaks

Open kusalananda opened this issue 8 years ago • 4 comments

There are a few memory leaks in MrBayes:

  • Memory allocated in AllocTaxa() for speciespartitionId[i] is not freed.
  • Memory allocated in AllocateTree() for t, t->nodes, and t->allDownPass is not freed.

This was found with Valgrind running the example in bug #28 reported by @zhangchicool and may be a side-effect of that bug.

kusalananda avatar Aug 01 '16 11:08 kusalananda

There are further memory leaks if we link with GNU Readline, but those are not leaks that we can do anything about. It's only a question about a few bytes per typed-in command (the actual command strings themselves), and has to do with command line history that is not freed when the process terminates.

kusalananda avatar Aug 04 '16 16:08 kusalananda

The first leak, in AllocTaxa() comes from setting numTaxa = 0 in FreeTaxa() before using this variable in a deallocation loop. I'm fixing this.

kusalananda avatar Sep 07 '16 10:09 kusalananda

The other leak is a strange one, and I'm not sure how to fix it. It's the allocation of treeHandle in InitializeChainTrees() in model.c that leaks. That whole loop (for (i = from; i < to; i++)) is unusual, and the deallocation routine FreeModel() has no way of knowing how to properly deallocate mcmcTree, which is a Tree **.

kusalananda avatar Sep 07 '16 12:09 kusalananda

I've fixed part of the leak from the MCMC tree allocation code, but when running the examples/primates.nex file I still have a couple of leaks from the same code showing up under Valgrind (. Is it possible that numGlobalChains changes after allocation and that I can't use that for looping?

EDIT: No, wait. I think I found it. It's memory in AllocateTree() that isn't freed.

EDIT: Aw shucks, close but no cigar.

kusalananda avatar Sep 19 '16 14:09 kusalananda