Fix mem leak and crash
Merge branch 'master' into peercoin