Fixes #42232. And fixes memory leak with use of DirAccess, and harmonize the use of the sanitized pkg name. (cherry picked from commits707a62783band02d228554b)
Fixes #42232. And fixes memory leak with use of DirAccess, and harmonize the use of the sanitized pkg name. (cherry picked from commits707a62783band02d228554b)