Skip to content

Commit

Permalink
Merge pull request #1447 from jthiltges/tempca-free
Browse files Browse the repository at this point in the history
[XrdTls] Memory leak fixes in XrdTlsTempCA
  • Loading branch information
abh3 committed Apr 23, 2021
2 parents 465579d + aa52817 commit 4ca38eb
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/XrdTls/XrdTlsTempCA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ CASet::processFile(file_smart_ptr &fp, const std::string &fname)
XrdCryptosslX509ParseFile(fp.get(), &chain, fname.c_str());

auto ca = chain.Begin();
// Note we purposely leak the outputfp here; we are just borrowing the handle.
FILE *outputfp = fdopen(m_output_fd, "w");
if (!outputfp) {
file_smart_ptr outputfp(fdopen(XrdSysFD_Dup(m_output_fd), "w"), &fclose);
if (!outputfp.get()) {
m_log.Emsg("CAset", "Failed to reopen file for output", fname.c_str());
chain.Cleanup();
return false;
}
while (ca) {
Expand All @@ -120,13 +120,15 @@ CASet::processFile(file_smart_ptr &fp, const std::string &fname)
//m_log.Emsg("CAset", "New CA with hash", fname.c_str(), hash_ptr);
m_known_cas.insert(hash_ptr);

if (XrdCryptosslX509ToFile(ca, outputfp, fname.c_str())) {
if (XrdCryptosslX509ToFile(ca, outputfp.get(), fname.c_str())) {
m_log.Emsg("CAset", "Failed to write out CA", fname.c_str());
chain.Cleanup();
return false;
}
ca = chain.Next();
}
fflush(outputfp);
fflush(outputfp.get());
chain.Cleanup();

return true;
}
Expand Down Expand Up @@ -166,9 +168,8 @@ class CRLSet {
bool
CRLSet::processFile(file_smart_ptr &fp, const std::string &fname)
{
// Note we purposely leak the outputfp here; we are just borrowing the handle.
FILE *outputfp = fdopen(m_output_fd, "w");
if (!outputfp) {
file_smart_ptr outputfp(fdopen(dup(m_output_fd), "w"), &fclose);
if (!outputfp.get()) {
m_log.Emsg("CAset", "Failed to reopen file for output", fname.c_str());
return false;
}
Expand All @@ -191,13 +192,13 @@ CRLSet::processFile(file_smart_ptr &fp, const std::string &fname)
//m_log.Emsg("CRLset", "New CRL with hash", fname.c_str(), hash_ptr);
m_known_crls.insert(hash_ptr);

if (!xrd_crl->ToFile(outputfp)) {
if (!xrd_crl->ToFile(outputfp.get())) {
m_log.Emsg("CRLset", "Failed to write out CRL", fname.c_str());
fflush(outputfp);
fflush(outputfp.get());
return false;
}
}
fflush(outputfp);
fflush(outputfp.get());

return true;
}
Expand Down

0 comments on commit 4ca38eb

Please sign in to comment.