On Thu, Jan 23, 2020 at 04:27:41PM +0800, Xan Phung wrote: > Hi, I use Sparse's domtree_build() as the basis of my C implementation of > the "Relooper" algorithm. I notice domtree_build appears to have a "memory > leak" (this is an oversimplification of the problem, but not far off the > truth). > > Specifically, each time domtree_build gets called, extraneous/duplicated > child nodes get left in the bb->doms ptrlist. This is because the existing > children are not cleared from bb->doms ptr list before rebuilding it. (If > you want to reproduce this problem, I can supply a demo of it comprising a > test input source file and a modified test-linearized.c, which calls > domtree_build repeatedly and reports the memory allocation stats). > > In addition to consuming memory, the extraneous child nodes cause problems > with my Relooper algorithm (as it results in a malformed dominance tree > when walking down bb->doms). Yes, indeed. The leak is one thing but the correctness is another one. > The following 3 line patch fixes this problem: Yes, that should do it. Thank you. For me to take your patch would you mind to add your Signed-off-by, certifying that you wrote the patch? Details can be found, for example, at https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin -- Luc