masks: fix huge memory leak