Overlay: fix crash on mask and some memory leak.
Merge pull request #39 from innocenat/overlay-fix

Overlay: fix crash on mask and some memory leak.