Parsing recursion causes memory leak in libvala
When using libvala to parse code that contains recursion, a number of objects are not freed. This happens somewhere during the SemanticAnalyzer pass, as if the SemanticAnalyzer does not run, no leak occurs.
Code as simple as the below triggers the issue and can be seen as still reachable memory in valgrind. In fact, even libvala parsing the below code once can leave around 0.5 MB of memory unfreed. So running the parser multiple times on a larger codebase causes some serious issues.
public static void test () {
if (1 == 2) {
test ();
}
}
public static int main (string[] args) {
return 0;
}
Using some systemtap scripts, I am able to find that the objects left alive as a result of parsing the above code are:
Alive objects:
16 ValaArrayList
3 ValaScope
3 ValaVoidType
11 ValaSourceReference
1 ValaMethod
2 ValaBlock
2 ValaIntegerLiteral
1 ValaBinaryExpression
1 ValaMemberAccess
1 ValaMethodCall
1 ValaExpressionStatement
1 ValaIfStatement
2 ValaBooleanType
4 ValaIntegerType
1 ValaVersionAttribute
1 ValaMethodType
I haven't yet been able to track down the source of the leak, but so far I suspect it to be a cyclic reference containing Vala.Scope
. I will continue trying to track this, but it is proving to be quite elusive. So perhaps someone with better debugging skills than me may have more luck.