Fix memleak revealed by Coverity Scan
(cherry picked from commit ce45e6e69ddcf457471a409f61524de0229157bb)