backport the changesets cf4f141, 32ff087, 060679b, 8356363, fcb40e1
and 0366cc9 from master to fix the heap abuse, i.e. issue #24.