masks: fix another potential memory leak
(cherry picked from commit e189a71c211260366c8223f1de84a41a0a40d245)