Memleak fix branch

Do not merge yet