Merge pull request #44 from lategoodbye/master

fix some handling after memory allocation