the settings code was leaking and it was copy/pasted in a few files.

created a method to find QSettings (settings.h) and stopped it from leaking.

The leak looked like this...

==7800==    at 0x4C2726C: operator new(unsigned long) (vg_replace_malloc.c:230)
==7800==    by 0x64FD232: (within /usr/lib/libQtCore.so.4.5.0)
==7800==    by 0x64FDB62: QSettings::QSettings(QString const&, QString const&, Q
Object*) (in /usr/lib/libQtCore.so.4.5.0)
==7800==    by 0x4738E5: PfPvPlot::setData(RideItem*) (PfPvPlot.cpp:361)
This commit is contained in:
Greg Lonnon
2009-09-07 09:14:45 -06:00
committed by Sean Rhea
parent 5299810a7e
commit 243a28bb87
9 changed files with 32 additions and 62 deletions

View File

@@ -94,18 +94,12 @@ MainWindow::parseRideFileName(const QString &name, QString *notesFileName, QDate
}
MainWindow::MainWindow(const QDir &home) :
home(home), settings(NULL),
home(home),
zones(NULL), currentNotesChanged(false),
ride(NULL)
{
QDir tempHome = QDir();
if(!tempHome.exists("Library/GoldenCheetah"))
settings = new QSettings(GC_SETTINGS_CO, GC_SETTINGS_APP);
else
settings = new QSettings(tempHome.absolutePath()+"/gc", QSettings::IniFormat);
settings = GetApplicationSettings();
QVariant unit = settings->value(GC_UNIT);
useMetricUnits = (unit.toString() == "Metric");

View File

@@ -107,7 +107,7 @@ class MainWindow : public QMainWindow
void setHistBinWidthText();
void setHistTextValidator();
QSettings *settings;
boost::shared_ptr<QSettings> settings;
RideCalendar *calendar;
QSplitter *splitter;

View File

@@ -100,16 +100,8 @@ ManualRideDialog::ManualRideDialog(MainWindow *mainWindow,
// how to estimate BikeScore:
QLabel *BSEstLabel;
QSettings *settings;
//First check to see if the Library folder exists where the executable is (for USB sticks)
QDir tempHome = QDir();
if(!tempHome.exists("Library/GoldenCheetah"))
settings = new QSettings(GC_SETTINGS_CO, GC_SETTINGS_APP);
else
settings = new QSettings(home.absolutePath()+"/gc", QSettings::IniFormat);
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
QVariant BSmode = settings->value(GC_BIKESCOREMODE);

View File

@@ -27,13 +27,8 @@ ConfigurationPage::ConfigurationPage()
unitCombo = new QComboBox();
unitCombo->addItem(tr("Metric"));
unitCombo->addItem(tr("English"));
//First check to see if the Library folder exists where the executable is (for USB sticks)
QDir home = QDir();
QSettings *settings;
if(!home.exists("Library/GoldenCheetah"))
settings = new QSettings(GC_SETTINGS_CO, GC_SETTINGS_APP);
else
settings = new QSettings(home.absolutePath()+"/gc", QSettings::IniFormat);
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
QVariant unit = settings->value(GC_UNIT);

View File

@@ -162,13 +162,7 @@ PfPvPlot::PfPvPlot()
curve->setRenderHint(QwtPlotItem::RenderAntialiased);
curve->attach(this);
//First check to see if the Library folder exists where the executable is (for USB sticks)
QDir home = QDir();
QSettings *settings;
if(!home.exists("Library/GoldenCheetah"))
settings = new QSettings(GC_SETTINGS_CO, GC_SETTINGS_APP);
else
settings = new QSettings(home.absolutePath()+"/gc", QSettings::IniFormat);
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
cl_ = settings->value(GC_CRANKLENGTH).toDouble() / 1000.0;
@@ -360,13 +354,8 @@ PfPvPlot::setData(RideItem *_rideItem)
}
replot();
//First check to see if the Library folder exists where the executable is (for USB sticks)
QDir home = QDir();
QSettings *settings;
if(!home.exists("Library/GoldenCheetah"))
settings = new QSettings(GC_SETTINGS_CO, GC_SETTINGS_APP);
else
settings = new QSettings(home.absolutePath()+"/gc", QSettings::IniFormat);
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
setCL(settings->value(GC_CRANKLENGTH).toDouble() / 1000.0);
}

View File

@@ -205,13 +205,8 @@ PowerHist::PowerHist():
lny(false)
{
QDir home = QDir();
QSettings *settings;
if(!home.exists("Library/GoldenCheetah"))
settings = new QSettings(GC_SETTINGS_CO, GC_SETTINGS_APP);
else
settings = new QSettings(home.absolutePath()+"/gc", QSettings::IniFormat);
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
unit = settings->value(GC_UNIT);
useMetricUnits = (unit.toString() == "Metric");

View File

@@ -192,13 +192,7 @@ QStringList RideFileFactory::listRideFiles(const QDir &dir) const
filters << ("*." + i.key());
}
// This will read the user preferences and change the file list order as necessary:
//First check to see if the Library folder exists where the executable is (for USB sticks)
QDir home = QDir();
QSettings *settings;
if(!home.exists("Library/GoldenCheetah"))
settings = new QSettings(GC_SETTINGS_CO, GC_SETTINGS_APP);
else
settings = new QSettings(home.absolutePath()+"/gc", QSettings::IniFormat);
boost::shared_ptr<QSettings> settings = GetApplicationSettings();;
QVariant isAscending = settings->value(GC_ALLRIDES_ASCENDING,Qt::Checked);
if(isAscending.toInt()>0){

View File

@@ -92,13 +92,8 @@ static void summarize(QString &intervals,
intervals = intervals.arg(watts_avg, 0, 'f', 0);
intervals = intervals.arg(hr_avg, 0, 'f', 0);
intervals = intervals.arg(cad_avg, 0, 'f', 0);
//First check to see if the Library folder exists where the executable is (for USB sticks)
QDir home = QDir();
QSettings *settings;
if(!home.exists("Library/GoldenCheetah"))
settings = new QSettings(GC_SETTINGS_CO, GC_SETTINGS_APP);
else
settings = new QSettings(home.absolutePath()+"/gc", QSettings::IniFormat);
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
QVariant unit = settings->value(GC_UNIT);
if(unit.toString() == "Metric")

View File

@@ -37,5 +37,21 @@
#define GC_BIKESCOREDAYS "bikeScoreDays"
#define GC_BIKESCOREMODE "bikeScoreMode"
#include <QSettings>
#include <boost/shared_ptr.hpp>
inline boost::shared_ptr<QSettings> GetApplicationSettings()
{
boost::shared_ptr<QSettings> settings;
QDir home = QDir();
//First check to see if the Library folder exists where the executable is (for USB sticks)
if(!home.exists("Library/GoldenCheetah"))
settings = boost::shared_ptr<QSettings>(new QSettings(GC_SETTINGS_CO, GC_SETTINGS_APP));
else
settings = boost::shared_ptr<QSettings>(new QSettings(home.absolutePath()+"/gc", QSettings::IniFormat));
return settings;
}
#endif // _GC_Settings_h