Merge pull request #2182 from csoler/v0.6-MemLeaks

Fixing mem leaks
This commit is contained in:
csoler 2020-12-30 20:58:32 +01:00 committed by GitHub
commit 159a2061f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 132 additions and 119 deletions

View file

@ -258,8 +258,7 @@ int p3discovery2::handleIncoming()
++nhandled;
Dbg4() << __PRETTY_FUNCTION__ << " Received item: " << std::endl
<< *item << std::endl;
Dbg4() << __PRETTY_FUNCTION__ << " Received item: " << *item << std::endl;
if((contact = dynamic_cast<RsDiscContactItem *>(item)) != nullptr)
{
@ -269,30 +268,26 @@ int p3discovery2::handleIncoming()
processContactInfo(item->PeerId(), contact);
}
else if( (gxsidlst = dynamic_cast<RsDiscIdentityListItem *>(item)) != nullptr )
{
recvIdentityList(item->PeerId(),gxsidlst->ownIdentityList);
delete item;
}
else if((pgpkey = dynamic_cast<RsDiscPgpKeyItem *>(item)) != nullptr)
recvPGPCertificate(item->PeerId(), pgpkey);
else if((pgpcert = dynamic_cast<RsDiscPgpCertItem *>(item)) != nullptr)
// sink
delete pgpcert;
RsWarn() << "Received a deprecated RsDiscPgpCertItem. Will not be handled." << std::endl; // nothing to do.
else if((pgplist = dynamic_cast<RsDiscPgpListItem *>(item)) != nullptr)
{
if (pgplist->mode == RsGossipDiscoveryPgpListMode::FRIENDS)
processPGPList(pgplist->PeerId(), pgplist);
else if (pgplist->mode == RsGossipDiscoveryPgpListMode::GETCERT)
recvPGPCertificateRequest(pgplist->PeerId(), pgplist);
else delete item;
}
else
{
RsWarn() << __PRETTY_FUNCTION__ << " Received unknown item type " << (int)item->PacketSubType() << "! " << std::endl ;
RsWarn() << item << std::endl;
delete item;
}
}
delete item;
}
return nhandled;
}
@ -350,8 +345,6 @@ void p3discovery2::sendOwnContactInfo(const RsPeerId &sslid)
void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContactItem *item)
{
std::unique_ptr<const RsDiscContactItem> pitem(item); // ensures that item will be destroyed whichever door we leave through
#ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::recvOwnContactInfo()";
std::cerr << std::endl;
@ -678,7 +671,6 @@ void p3discovery2::processPGPList(const RsPeerId &fromId, const RsDiscPgpListIte
#endif
// cleanup.
delete item;
return;
}
@ -716,9 +708,6 @@ void p3discovery2::processPGPList(const RsPeerId &fromId, const RsDiscPgpListIte
it->second.mergeFriendList(item->pgpIdSet.ids);
updatePeers_locked(fromId);
// cleanup.
delete item;
}
@ -913,7 +902,6 @@ void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContac
if(sockaddr_storage_isExternalNet(item->currentConnectAddress.addr))
mPeerMgr->addCandidateForOwnExternalAddress(item->PeerId(), item->currentConnectAddress.addr);
delete item;
return;
}
@ -942,7 +930,6 @@ void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContac
/* inform NetMgr that we know this peer */
mNetMgr->netAssistKnownPeer(item->sslId, item->extAddrV4.addr, NETASSIST_KNOWN_PEER_FOF | NETASSIST_KNOWN_PEER_OFFLINE);
}
delete item;
return;
}
@ -991,8 +978,6 @@ void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContac
if(should_notify_discovery)
RsServer::notify()->notifyDiscInfoChanged();
delete item;
}
/* we explictly request certificates, instead of getting them all the time
@ -1041,8 +1026,6 @@ void p3discovery2::recvPGPCertificateRequest( const RsPeerId& fromId, const RsDi
sendPGPCertificate(pgpId, fromId);
else
std::cerr << "(WW) not sending certificate " << pgpId << " asked by friend " << fromId << " because this either this cert is not a friend, or discovery is off" << std::endl;
delete item;
}
@ -1119,7 +1102,6 @@ void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem*
#endif
// now that will add the key *and* set the skip_signature_validation flag at once
rsPeers->loadPgpKeyFromBinaryData((unsigned char*)item->bin_data,item->bin_len, tmp_pgp_id,error_string); // no error should occur at this point because we called loadDetailsFromStringCert() already
delete item;
// Make sure we allow connections after the key is added. This is not the case otherwise. We only do that if the peer is non validated peer, since
// otherwise the connection should already be accepted. This only happens when the short invite peer sends its own PGP key.

View file

@ -1238,14 +1238,6 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
RsErr() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl;
// if(rsEvents)
// {
// ev->mErrorMsg = errMsg;
// ev->mErrorCode = RsAuthSslConnectionAutenticationEvent::NO_CERTIFICATE_SUPPLIED;
//
// rsEvents->postEvent(std::move(ev));
// }
return verificationFailed;
}
@ -1400,8 +1392,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
return verificationFailed;
}
//setCurrentConnectionAttemptInfo(pgpId, sslId, sslCn);
LocalStoreCert(x509Cert);
LocalStoreCert(x509Cert);
RsInfo() << __PRETTY_FUNCTION__ << " authentication successfull for "
<< "sslId: " << sslId << " isSslOnlyFriend: " << isSslOnlyFriend
@ -1410,9 +1401,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
return verificationSuccess;
}
bool AuthSSLimpl::parseX509DetailsFromFile(
const std::string& certFilePath, RsPeerId& certId,
RsPgpId& issuer, std::string& location )
bool AuthSSLimpl::parseX509DetailsFromFile( const std::string& certFilePath, RsPeerId& certId, RsPgpId& issuer, std::string& location )
{
FILE* tmpfp = RsDirUtil::rs_fopen(certFilePath.c_str(), "r");
if(!tmpfp)
@ -1433,11 +1422,14 @@ bool AuthSSLimpl::parseX509DetailsFromFile(
}
uint32_t diagnostic = 0;
if(!AuthX509WithGPG(x509,false, diagnostic))
{
RsErr() << __PRETTY_FUNCTION__ << " AuthX509WithGPG failed with "
<< "diagnostic: " << diagnostic << std::endl;
return false;
X509_free(x509);
return false;
}
certId = RsX509Cert::getCertSslId(*x509);
@ -1805,26 +1797,28 @@ bool AuthSSLimpl::loadList(std::list<RsItem*>& load)
for(it = load.begin(); it != load.end(); ++it) {
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
if(vitem) {
#ifdef AUTHSSL_DEBUG
if(vitem)
{
#ifdef AUTHSSL_DEBUG
std::cerr << "AuthSSLimpl::loadList() General Variable Config Item:" << std::endl;
vitem->print(std::cerr, 10);
std::cerr << std::endl;
#endif
#endif
std::list<RsTlvKeyValue>::iterator kit;
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) {
if (RsPeerId(kit->key) == mOwnId) {
continue;
}
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
{
if (RsPeerId(kit->key) == mOwnId) {
continue;
}
X509 *peer = loadX509FromPEM(kit->value);
/* authenticate it */
uint32_t diagnos ;
if (AuthX509WithGPG(peer,false,diagnos))
{
LocalStoreCert(peer);
}
X509 *peer = loadX509FromPEM(kit->value);
/* authenticate it */
uint32_t diagnos ;
if (peer && AuthX509WithGPG(peer,false,diagnos))
LocalStoreCert(peer);
X509_free(peer);
}
}
delete (*it);