Fixed minor memory leak when changing image masks.