[gsharedvt] Fix memory leaks. Fixes #16787.