diff options
author | Harald Fernengel <harald.fernengel@nokia.com> | 2010-10-29 11:57:18 (GMT) |
---|---|---|
committer | Harald Fernengel <harald.fernengel@nokia.com> | 2010-10-29 11:58:26 (GMT) |
commit | aaba8c808d02bfd8a5208260320ce522b84954a1 (patch) | |
tree | 7a3572289de97e3d0c809a7a25dd37461423d413 | |
parent | c02ef9eb331f03dbd59d2fd938c53b54f5c65cea (diff) | |
download | Qt-aaba8c808d02bfd8a5208260320ce522b84954a1.zip Qt-aaba8c808d02bfd8a5208260320ce522b84954a1.tar.gz Qt-aaba8c808d02bfd8a5208260320ce522b84954a1.tar.bz2 |
Fix memory leak on exit
The confFile was lost if the cache was already gone (e.g. on app exit).
This patch ensures that the confFile is always deleted.
Reviewed-by: João Abecasis
-rw-r--r-- | src/corelib/io/qsettings.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 53af822..8ee42e7 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -1231,16 +1231,21 @@ QConfFileSettingsPrivate::~QConfFileSettingsPrivate() if (confFiles[i] && !confFiles[i]->ref.deref()) { if (confFiles[i]->size == 0) { delete confFiles[i].take(); - } else if (unusedCache) { + } else { if (usedHash) usedHash->remove(confFiles[i]->name); - QT_TRY { - // compute a better size? - unusedCache->insert(confFiles[i]->name, confFiles[i].data(), - 10 + (confFiles[i]->originalKeys.size() / 4)); - confFiles[i].take(); - } QT_CATCH(...) { - // out of memory. Do not cache the file. + if (unusedCache) { + QT_TRY { + // compute a better size? + unusedCache->insert(confFiles[i]->name, confFiles[i].data(), + 10 + (confFiles[i]->originalKeys.size() / 4)); + confFiles[i].take(); + } QT_CATCH(...) { + // out of memory. Do not cache the file. + delete confFiles[i].take(); + } + } else { + // unusedCache is gone - delete the entry to prevent a memory leak delete confFiles[i].take(); } } |