Better fix for gradient slider. This replaces 5e57fafa0d78
Coverity CID 1034359

(cherry picked from commit 26c3204dd21fda921c678e118ed90fa94f7d80a3)
Fix multiple (potential?) memleaks in masks. Anything broken?
Coverity CID 1125109, CID 1125110, CID 1147481, CID 1147482, CID 1147483, CID 1147484, CID 1147485, CID 1147486, CID 1147487, CID 1147488, CID 1147489

(cherry picked from commit b5cf6c950513f8b467153562f09d71633bc02d92)