Skip to content

Commit

Permalink
Fix issue of possible dead reference to Options
Browse files Browse the repository at this point in the history
Drive and Options are both Singlton, their destruct sequence is
random. To avoid the dead reference, Drive destructor should not
reference to Options.
  • Loading branch information
jimhuaang committed May 26, 2018
1 parent 4ef3d50 commit 27b29ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/filesystem/Drive.cpp
Expand Up @@ -117,6 +117,8 @@ Drive::Drive()
: m_mountable(true),
m_cleanup(false),
m_connect(false),
m_diskCacheFolder(
QS::Configure::Options::Instance().GetDiskCacheDirectory()),
m_client(ClientFactory::Instance().MakeClient()),
m_transferManager(
TransferManagerFactory::Create(TransferManagerConfigure())) {
Expand Down Expand Up @@ -150,11 +152,9 @@ void Drive::CleanUp() {
if (!GetCleanup()) {
// remove disk cache folder if existing
// log off, to avoid dead reference to log (a singleton)
string diskfolder =
QS::Configure::Options::Instance().GetDiskCacheDirectory();
if (QS::Utils::FileExists(diskfolder) &&
QS::Utils::IsDirectory(diskfolder).first) {
DeleteFilesInDirectory(diskfolder, true); // delete folder itself
if (QS::Utils::FileExists(m_diskCacheFolder) &&
QS::Utils::IsDirectory(m_diskCacheFolder).first) {
DeleteFilesInDirectory(m_diskCacheFolder, true); // delete folder itself
}

m_client.reset();
Expand Down
2 changes: 2 additions & 0 deletions src/filesystem/Drive.h
Expand Up @@ -285,6 +285,8 @@ class Drive : public Singleton<Drive> {

bool m_connect; // denote if drive connected to storage

std::string m_diskCacheFolder;

boost::shared_ptr<QS::Client::Client> m_client;
boost::shared_ptr<QS::Client::TransferManager> m_transferManager;
boost::shared_ptr<QS::Data::Cache> m_cache;
Expand Down

0 comments on commit 27b29ec

Please sign in to comment.