I have 2 legacy wallets and on both if I run `upgradewallet` it will cause bitcoin core to crash. This should just return me an error string

Currenl result from `getwalletinfo`:
```
{
  "walletname": "Wallet",
  "walletversion": 169900,
  "format": "bdb",
  "balance": 0.00000000,
  "unconfirmed_balance": 0.00000000,
  "immature_balance": 0.00000000,
  "txcount": 80,
  "keypoololdest": 1613078825,
  "keypoolsize": 941,
  "keypoolsize_hd_internal": 941,
  "paytxfee": 0.00000000,
  "private_keys_enabled": false,
  "avoid_reuse": true,
  "scanning": false,
  "descriptors": false
}
```
{
    LOCK(cs_KeyStore);
    std::vector<WalletDestination> result;
    
    for (const auto& keyid : GetAffectedKeys(script, *this)) {
        std::map<CKeyID, int64_t>::const_iterator mi = m_pool_key_to_index.find(keyid);
        if (mi != m_pool_key_to_index.end()) {
            WalletLogPrintf("%s: Detected a used keypool key, mark all keypool keys up to this key as used\n", __func__);
            for (const auto& keypool : MarkReserveKeysAsUsed(mi->second)) {
                
                for (const auto& type : LEGACY_OUTPUT_TYPES) {
                    const auto& dest = GetDestinationForKey(keypool.vchPubKey, type);
                    result.push_back({dest, keypool.fInternal});
                }
            }
            if (!TopUp()) {
                WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", __func__);
            }
        }