Jqlite data leak

This PR sits on top of #7942 so only the last commit is relevant here while the previous PR is not merged into master.