fix memory leak

Found by Lsan. Upstreamed Libreoffice patch.