Reference leak of a loop-local variable when continuing a loop from within a switch
If a dynamically allocated Vala variable is local to each iteration of a loop, and the loop contains a switch, and one branch of the switch ends with continue
, then the variable can fail to be unreffed.
In the following source file, I loop over a linked list, and inside each loop, I construct a variable of class Logger
, whose job is to have side effects when it is constructed and destructed.
Expected result: regardless of what happens inside the loop, each instance of Logger
should be unreffed and freed when the loop iteration finishes in any way. So I would expect a "Logger #n destructed" message for each of the three loop iterations.
Actual result: as you can see in the transcript below, the Logger
corresponding to the list node with index 1 (when the continue
clause of the switch is run) does not run its destructor. You can see that no destructor message ends with "(continued)". Looking at the C, there is no call to _logger_unref0
inside the switch statement.
Source file: test.vala
Transcript:
$ valac --version
Vala 0.44.3
$ valac test.vala
$ ./test
Logger #0 constructed
Logger #0 destructed ('did not continue')
Logger #1 constructed
Logger #2 constructed
Logger #2 destructed ('did not continue')
$