MrBayes
MrBayes copied to clipboard
Memory leaks
There are a few memory leaks in MrBayes:
- Memory allocated in
AllocTaxa()
forspeciespartitionId[i]
is not freed. - Memory allocated in
AllocateTree()
fort
,t->nodes
, andt->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.
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.
The first leak, in AllocTaxa()
comes from setting numTaxa = 0
in FreeTaxa()
before using this variable in a deallocation loop. I'm fixing this.
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 **
.
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.