Commit ee338c55 authored by Christian Esken's avatar Christian Esken
Browse files

Remove some memory leaks. Mainly cleanup for shutdown, but also for (dynamic)...

Remove some memory leaks. Mainly cleanup for shutdown, but also for (dynamic) controls. Makes valgrind output easier to inspect for relevant leaks.
CCBUGS: 309464
parent 6e7fb0b5
......@@ -143,6 +143,14 @@ KMixWindow::~KMixWindow()
}
// -2- Mixer HW
MixerToolBox::instance()->deinitMixer();
// GUIProfile cache should be cleared very very late, as GUIProfile instances are used in the Views, which
// means main window and potentially also in the tray popup (at least we might do so in the future).
// This place here could be to early, if we would start to GUIProfile outside KMixWIndow, e.g. in the tray popup.
// Until we do so, this is the best place to call clearCache(). Later, e.g. in main() would likely be problematic.
GUIProfile::clearCache();
}
......
......@@ -120,7 +120,11 @@ int Mixer_ALSA::open()
snd_mixer_elem_t *elem;
snd_mixer_selem_id_t *sid;
snd_mixer_selem_id_alloca( &sid );
bool USE_ALSO_ALLOCA = true; // TODO remove alloca() when adding "delete sid" in the destructor or close()
if (USE_ALSO_ALLOCA)
{
snd_mixer_selem_id_alloca( &sid );
}
// Determine a card name
if( m_devnum < -1 || m_devnum > 31 )
......@@ -211,14 +215,25 @@ int Mixer_ALSA::open()
MixDevice* mdNew = new MixDevice(_mixer, finalMixdeviceID, readableName, ct );
if ( volPlay != 0 ) mdNew->addPlaybackVolume(*volPlay);
if ( volCapture != 0 ) mdNew->addCaptureVolume (*volCapture);
if ( !enumList.isEmpty() ) mdNew->addEnums(enumList);
if ( volPlay != 0 )
{
mdNew->addPlaybackVolume(*volPlay);
delete volPlay;
}
if ( volCapture != 0 )
{
mdNew->addCaptureVolume (*volCapture);
delete volCapture;
}
if ( !enumList.isEmpty() )
{
mdNew->addEnums(enumList);
qDeleteAll(enumList); // clear temporary list
}
shared_ptr<MixDevice> md = mdNew->addToPool();
m_mixDevices.append( md );
qDeleteAll(enumList); // clear temporary list
// --- Recommended master ----------------------------------------
if ( md->playbackVolume().hasVolume() )
......@@ -253,10 +268,6 @@ int Mixer_ALSA::open()
m_recommendedMaster = md;
masterChosenQuality = 30;
}
//kDebug() << "ALSA create MDW, vol= " << *vol;
delete volPlay;
delete volCapture;
}
} // for all elems
......
......@@ -60,6 +60,8 @@ int Mixer_MPRIS2::close()
{
m_isOpen = false;
closeCommon();
qDeleteAll(controls);
controls.clear();
return 0;
}
......@@ -469,6 +471,8 @@ void Mixer_MPRIS2::plugControlIdIncoming(QDBusPendingCallWatcher* watcher)
m_mixDevices.append( mdNew->addToPool() );
delete vol; // vol is only temporary. mdNew has its own volume object. => delete
QDBusConnection sessionBus = QDBusConnection::sessionBus();
sessionBus.connect(busDestination, QString("/org/mpris/MediaPlayer2"), "org.freedesktop.DBus.Properties", "PropertiesChanged", mad, SLOT(volumeChangedIncoming(QString,QVariantMap,QStringList)) );
connect(mad, SIGNAL(volumeChanged(MPrisControl*,double)), this, SLOT(volumeChanged(MPrisControl*,double)) );
......@@ -585,7 +589,10 @@ MPrisControl::MPrisControl(QString id, QString busDestination)
}
MPrisControl::~MPrisControl()
{}
{
delete propertyIfc;
delete playerIfc;
}
QString Mixer_MPRIS2::getDriverName()
{
......
......@@ -76,6 +76,9 @@ bool ProductComparator::operator()(const ProfProduct* p1, const ProfProduct* p2)
GUIProfile::GUIProfile()
{
_dirty = false;
_driverVersionMin = 0;
_driverVersionMax = 0;
_generation = 1;
}
GUIProfile::~GUIProfile()
......@@ -85,6 +88,19 @@ GUIProfile::~GUIProfile()
qDeleteAll(_products);
}
/**
* Clears the GUIProfile cache. You must only call this
* before termination of the application, as GUIProfile instances are used in other classes, especially the views.
* There is no need to call this in non-GUI applications like kmixd and kmixctrl.
*/
void GUIProfile::clearCache()
{
qDeleteAll(s_profiles);
s_profiles.clear();
}
void GUIProfile::setId(const QString& id)
{
......@@ -240,7 +256,6 @@ void GUIProfile::addProfile(GUIProfile* guiprof)
s_profiles[guiprof->getId()] = guiprof;
kDebug() << "I have added" << guiprof->getId() << "; Number of profiles is now " << s_profiles.size() ;
}
......@@ -666,6 +681,7 @@ QString ProfControl::renderSubcontrols()
GUIProfileParser::GUIProfileParser(GUIProfile* ref_gp) : _guiProfile(ref_gp)
{
_scope = GUIProfileParser::NONE; // no scope yet
}
bool GUIProfileParser::startDocument()
......
......@@ -135,6 +135,8 @@ class GUIProfile
GUIProfile();
virtual ~GUIProfile();
static void clearCache();
bool readProfile(const QString& ref_fileNamestring);
bool finalizeProfile() const;
bool writeProfile();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment