Overlay: fix crash on mask and some memory leak.

as title says.