Problem: Using submatch() in a lambda passed to substitute() is verbose.
Solution: Use a static list and pass it as an optional argument to the
function. Fix memory leak.
Problem: Coverity complains about not restoring a value.
Solution: Restore the value, although it's not really needed. Change return
to jump to cleanup, might leak memory.