Fix memory leak (ROOT-6116).

(cherry picked from commit cda6480dd28f6d75406f8e3351644a8a7c7783cb)