Skip to content

Commit

Permalink
In destructor properly check if Info struct is created.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja committed Jun 15, 2016
1 parent 63694a5 commit 3c56d49
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/XrdFileCache/XrdFileCacheFile.cc
Expand Up @@ -104,33 +104,39 @@ void File::BlockRemovedFromWriteQ(Block* b)

File::~File()
{
m_syncStatusMutex.Lock();
bool needs_sync = ! m_writes_during_sync.empty();
m_syncStatusMutex.UnLock();
if (needs_sync || m_non_flushed_cnt > 0)
if (m_infoFile)
{
Sync();
m_cfi.WriteHeader(m_infoFile);
}
// write statistics in *cinfo file
AppendIOStatToFileInfo();
m_infoFile->Fsync();
m_syncStatusMutex.Lock();

delete m_syncer;
m_syncer = NULL;
bool needs_sync = ! m_writes_during_sync.empty();
m_syncStatusMutex.UnLock();
if (needs_sync || m_non_flushed_cnt > 0)
{
Sync();
m_cfi.WriteHeader(m_infoFile);
}

// write statistics in *cinfo file
AppendIOStatToFileInfo();
m_infoFile->Fsync();

m_syncStatusMutex.UnLock();


m_infoFile->Close();
delete m_infoFile;
m_infoFile = NULL;
}

if (m_output)
{
m_output->Close();
delete m_output;
m_output = NULL;
}
if (m_infoFile)
{
m_infoFile->Close();
delete m_infoFile;
m_infoFile = NULL;
}

delete m_syncer;
m_syncer = NULL;

// print just for curiosity
TRACEF(Debug, "File::~File() ended, prefetch score = " << m_prefetchScore);
Expand Down Expand Up @@ -215,7 +221,7 @@ bool File::Open()
int res = m_output->Open(m_temp_filename.c_str(), O_RDWR, 0600, myEnv);
if (res < 0)
{
TRACEF(Error, "File::Open() can't open data file");
TRACEF(Error, "File::Open() can't open data file, " << strerror(errno));
delete m_output;
m_output = 0;
return false;
Expand All @@ -241,7 +247,7 @@ bool File::Open()
int res = m_infoFile->Open(ifn.c_str(), O_RDWR, 0600, myEnv);
if (res < 0)
{
TRACEF(Error, "File::Open() can't open info file");
TRACEF(Error, "File::Open() can't open info file, " << strerror(errno));
delete m_infoFile;
m_infoFile = 0;
return false;
Expand Down

0 comments on commit 3c56d49

Please sign in to comment.