[libcalamares] Slightly more memory-safe
Use unique_ptr to ensure Private is always deleted. SEE #1758
This commit is contained in:
parent
0899eefde7
commit
3519697d0e
@ -92,7 +92,7 @@ struct TemporaryMount::Private
|
|||||||
|
|
||||||
|
|
||||||
TemporaryMount::TemporaryMount( const QString& devicePath, const QString& filesystemName, const QString& options )
|
TemporaryMount::TemporaryMount( const QString& devicePath, const QString& filesystemName, const QString& options )
|
||||||
: m_d( new Private )
|
: m_d( std::make_unique<Private>() )
|
||||||
{
|
{
|
||||||
m_d->m_devicePath = devicePath;
|
m_d->m_devicePath = devicePath;
|
||||||
m_d->m_mountDir.setAutoRemove( false );
|
m_d->m_mountDir.setAutoRemove( false );
|
||||||
@ -100,8 +100,7 @@ TemporaryMount::TemporaryMount( const QString& devicePath, const QString& filesy
|
|||||||
if ( r )
|
if ( r )
|
||||||
{
|
{
|
||||||
cWarning() << "Mount of" << devicePath << "on" << m_d->m_mountDir.path() << "failed, code" << r;
|
cWarning() << "Mount of" << devicePath << "on" << m_d->m_mountDir.path() << "failed, code" << r;
|
||||||
delete m_d;
|
m_d.reset();
|
||||||
m_d = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +114,6 @@ TemporaryMount::~TemporaryMount()
|
|||||||
cWarning() << "UnMount of temporary" << m_d->m_devicePath << "on" << m_d->m_mountDir.path()
|
cWarning() << "UnMount of temporary" << m_d->m_devicePath << "on" << m_d->m_mountDir.path()
|
||||||
<< "failed, code" << r;
|
<< "failed, code" << r;
|
||||||
}
|
}
|
||||||
delete m_d;
|
|
||||||
m_d = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace CalamaresUtils
|
namespace CalamaresUtils
|
||||||
{
|
{
|
||||||
namespace Partition
|
namespace Partition
|
||||||
@ -58,12 +60,12 @@ public:
|
|||||||
TemporaryMount& operator=( const TemporaryMount& ) = delete;
|
TemporaryMount& operator=( const TemporaryMount& ) = delete;
|
||||||
~TemporaryMount();
|
~TemporaryMount();
|
||||||
|
|
||||||
bool isValid() const { return m_d; }
|
bool isValid() const { return bool( m_d ); }
|
||||||
QString path() const;
|
QString path() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Private;
|
struct Private;
|
||||||
Private* m_d = nullptr;
|
std::unique_ptr< Private > m_d;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Partition
|
} // namespace Partition
|
||||||
|
Loading…
Reference in New Issue
Block a user