Memory leak fix by lkiv. Original commits can be found in: https://github.com/everial/en/commit/3c03f46089f2a6e31487292ca6872e331b8f1eb0 and https://github.com/everial/en/commit/d8b840409a533ed6fd65f985f1ec02137522ca33