fix error identified by valgrind
Merge pull request #2471 from WalterBright/valgrind-fix

fix error identified by valgrind