(from key.cpp)
void CKey::Reset()
{
fCompressedPubKey = false;
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
if (pkey == NULL)
throw key_error("CKey::CKey() : EC_KEY_new_by_curve_name failed");
fSet = false;
}
Clearly if before calling Reset() with pkey != null then you have a memory leak (the pkey value is overwritten). The problem is that, for example, CBasicKeyStore::GetKey() calls Reset() on an already instantiated CKey &keyOut.
There should be a EC_KEY_free(pkey); like in CKey::SetSecret(), and in CKey::CKey() before calling Reset() pkey shoud be initialized to NULL.