summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2012-03-15 15:26:42 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-20 12:49:47 +0100
commitd88ce96d7875744d6f265c6d4ba3208799b3786b (patch)
treed552622441a60712f1f108c88e21df55e6f43595
parent6e27dc35231d118e142250fee8fc0453e2a5489c (diff)
Fixed a memory leak in JsonDbCollator
Change-Id: Ib395af249f59193aac3939f7c7bb1ae540d22832 Reviewed-by: Kevin Simons <kevin.simons@nokia.com> Reviewed-by: Liang Qi <liang.qi@nokia.com>
-rw-r--r--src/common/jsondbcollator.cpp24
-rw-r--r--src/common/jsondbcollator_p.h1
2 files changed, 13 insertions, 12 deletions
diff --git a/src/common/jsondbcollator.cpp b/src/common/jsondbcollator.cpp
index 19726fe..61e0139 100644
--- a/src/common/jsondbcollator.cpp
+++ b/src/common/jsondbcollator.cpp
@@ -52,6 +52,12 @@
QT_BEGIN_NAMESPACE_JSONDB
+JsonDbCollatorPrivate::~JsonDbCollatorPrivate()
+{
+ if (collator)
+ ucol_close(collator);
+}
+
static const int collationStringsCount = 13;
static const char * const collationStrings[collationStringsCount] = {
"default",
@@ -87,19 +93,15 @@ JsonDbCollator::JsonDbCollator(const JsonDbCollator &other)
JsonDbCollator::~JsonDbCollator()
{
- if (!d->ref.deref()) {
- if (d->collator)
- ucol_close(d->collator);
- }
+ if (!d->ref.deref())
+ delete d;
}
JsonDbCollator &JsonDbCollator::operator=(const JsonDbCollator &other)
{
if (this != &other) {
- if (!d->ref.deref()) {
- if (d->collator)
- ucol_close(d->collator);
- }
+ if (!d->ref.deref())
+ delete d;
*d = *other.d;
d->ref.ref();
}
@@ -211,10 +213,8 @@ void JsonDbCollator::detach()
x->options = d->options;
x->modified = true;
x->collator = 0;
- if (!d->ref.deref()) {
- if (d->collator)
- ucol_close(d->collator);
- }
+ if (!d->ref.deref())
+ delete d;
d = x;
}
}
diff --git a/src/common/jsondbcollator_p.h b/src/common/jsondbcollator_p.h
index 3902369..5a76f29 100644
--- a/src/common/jsondbcollator_p.h
+++ b/src/common/jsondbcollator_p.h
@@ -73,6 +73,7 @@ public:
options(0),
collator(0)
{ ref.store(1); }
+ ~JsonDbCollatorPrivate();
int compare(ushort *s1, int len1, ushort *s2, int len2);
};