[libcalamares] Slightly more memory-safe

Use unique_ptr to ensure Private is always deleted.

SEE #1758
This commit is contained in:
Adriaan de Groot 2021-08-31 12:54:51 +02:00
parent 0899eefde7
commit 3519697d0e
2 changed files with 6 additions and 7 deletions

View File

@ -92,7 +92,7 @@ struct TemporaryMount::Private
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_mountDir.setAutoRemove( false );
@ -100,8 +100,7 @@ TemporaryMount::TemporaryMount( const QString& devicePath, const QString& filesy
if ( r )
{
cWarning() << "Mount of" << devicePath << "on" << m_d->m_mountDir.path() << "failed, code" << r;
delete m_d;
m_d = nullptr;
m_d.reset();
}
}
@ -115,8 +114,6 @@ TemporaryMount::~TemporaryMount()
cWarning() << "UnMount of temporary" << m_d->m_devicePath << "on" << m_d->m_mountDir.path()
<< "failed, code" << r;
}
delete m_d;
m_d = nullptr;
}
}

View File

@ -17,6 +17,8 @@
#include <QString>
#include <QStringList>
#include <memory>
namespace CalamaresUtils
{
namespace Partition
@ -58,12 +60,12 @@ public:
TemporaryMount& operator=( const TemporaryMount& ) = delete;
~TemporaryMount();
bool isValid() const { return m_d; }
bool isValid() const { return bool( m_d ); }
QString path() const;
private:
struct Private;
Private* m_d = nullptr;
std::unique_ptr< Private > m_d;
};
} // namespace Partition