fixes leaks on gradient generation