From d5dca07e22852541888d90f20f4c1111bb5781cd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 30 Aug 2017 06:12:14 -0400 Subject: [PATCH 1/3] Fix uninitialized values (valgrind report) --- src/modules/partition/gui/EncryptWidget.cpp | 1 + src/modules/welcome/checker/partman_devices.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/gui/EncryptWidget.cpp b/src/modules/partition/gui/EncryptWidget.cpp index 9fc7be59d..198f2ebe1 100644 --- a/src/modules/partition/gui/EncryptWidget.cpp +++ b/src/modules/partition/gui/EncryptWidget.cpp @@ -23,6 +23,7 @@ EncryptWidget::EncryptWidget( QWidget* parent ) : QWidget( parent ) + , m_state( EncryptionDisabled ) { setupUi( this ); diff --git a/src/modules/welcome/checker/partman_devices.c b/src/modules/welcome/checker/partman_devices.c index d417f3c0f..e2c2bb98f 100644 --- a/src/modules/welcome/checker/partman_devices.c +++ b/src/modules/welcome/checker/partman_devices.c @@ -112,7 +112,7 @@ process_device(PedDevice *dev) int check_big_enough(long long required_space) { - PedDevice *dev; + PedDevice *dev = NULL; ped_exception_fetch_all(); ped_device_probe_all(); From e26d5ab20636c4c67b01a202db4c47b96ca112ed Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 30 Aug 2017 07:46:01 -0400 Subject: [PATCH 2/3] Don't leak memory for allocated modules --- src/libcalamaresui/modulesystem/ModuleManager.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index dd7abdf29..d08cdf8dd 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -57,7 +57,13 @@ ModuleManager::ModuleManager( const QStringList& paths, QObject* parent ) ModuleManager::~ModuleManager() -{} +{ + // The map is populated with Module::fromDescriptor(), which allocates on the heap. + for( auto moduleptr : m_loadedModulesByInstanceKey ) + { + delete moduleptr; + } +} void From 0e96621b941e175f3ee1c2247511ba44b3e0bdf4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 30 Aug 2017 07:50:24 -0400 Subject: [PATCH 3/3] Don't leak memory when winnowing disk devices - Improve logging a little - Don't leak Device*, but delete the raw pointer when erasing - Document that DeviceInfo takes ownership and doesn't leak --- src/modules/partition/core/DeviceList.cpp | 24 +++++++++++++------ .../partition/core/PartitionCoreModule.cpp | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index 5bce4a0e3..055c18dbc 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -106,12 +106,22 @@ operator <<( QDebug& s, QList< Device* >::iterator& it ) return s; } +using DeviceList = QList< Device* >; + +static inline DeviceList::iterator +erase(DeviceList& l, DeviceList::iterator& it) +{ + Device* p = *it; + auto r = l.erase( it ); + if (p) + delete p; + return r; +} + QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) { bool writableOnly = (which == DeviceType::WritableOnly); - using DeviceList = QList< Device* >; - CoreBackend* backend = CoreBackendManager::self()->backend(); DeviceList devices = backend->scanDevices( true ); @@ -123,8 +133,8 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) ( *it )->deviceNode().startsWith( "/dev/zram" ) ) { - cDebug() << " .. Removing" << it; - it = devices.erase( it ); + cDebug() << " .. Removing zram" << it; + it = erase(devices, it ); } else if ( writableOnly && ( @@ -132,13 +142,13 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) isIso9660( *it ) ) ) { - cDebug() << " .. Removing" << it; - it = devices.erase( it ); + cDebug() << " .. Removing root-or-CD" << it; + it = erase(devices, it ); } else if ( (minimumSize >= 0) && !( (*it)->capacity() > minimumSize ) ) { cDebug() << " .. Removing too-small" << it; - it = devices.erase( it ); + it = erase(devices, it ); } else ++it; diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index ac22b2b7a..07c09c6d7 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -122,6 +122,7 @@ PartitionCoreModule::doInit() cDebug() << "node\tcapacity\tname\tprettyName"; for ( auto device : devices ) { + // Gives ownership of the Device* to the DeviceInfo object auto deviceInfo = new DeviceInfo( device ); m_deviceInfos << deviceInfo; cDebug() << device->deviceNode() << device->capacity() << device->name() << device->prettyName();