The new revision should address all the concerns discussed above. It could very well introduce new concerns, though! :-) I rebased on top of current master so that I can also update the GitLab CI pipeline appropriately.
Also, I fixed a couple of related memory leaks which I discovered while working on this MR.