What happens when an encrypted wallet runs out of keys?
If the key pool is empty and the wallet is locked it will use an old key instead of generating a new key. When wallet encryption was implemented the block creation code was changed to make sure different coinbase transactions are generated in that case.