[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE_3_3_BRANCH: kdelibs/kdecore/network
From: Thiago Macieira <thiago.macieira () kdemail ! net>
Date: 2005-01-07 16:53:01
Message-ID: 20050107165301.27F571BBE9 () office ! kde ! org
[Download RAW message or body]
CVS commit by thiago:
(Backport 1.40:1.41) Fix the memory leak in KResolverResults.
Also update the #ifdef. That's something that never got backported.
M +9 -30 kresolver.cpp 1.32.2.7
--- kdelibs/kdecore/network/kresolver.cpp #1.32.2.6:1.32.2.7
@@ -1,4 +1,4 @@
/* -*- C++ -*-
- * Copyright (C) 2003,2004 Thiago Macieira <thiago.macieira@kdemail.net>
+ * Copyright (C) 2003-2005 Thiago Macieira <thiago.macieira@kdemail.net>
*
*
@@ -186,5 +186,5 @@ KResolverEntry& KResolverEntry::operator
// class KResolverResults
-class KNetwork::KResolverResultsPrivate: public QShared
+class KNetwork::KResolverResultsPrivate
{
public:
@@ -195,17 +195,4 @@ public:
errorcode(0), syserror(0)
{ }
-
- // duplicate the data if necessary, while decreasing the reference count
- // on the original data
- inline void dup(KResolverResultsPrivate*& d)
- {
- if (!(d->count > 1))
- {
- d->deref();
- KResolverResultsPrivate *e = new KResolverResultsPrivate(*d);
- e->count = 1;
- d = e; // set the pointer
- }
- }
};
@@ -218,7 +205,7 @@ KResolverResults::KResolverResults()
// copy constructor
KResolverResults::KResolverResults(const KResolverResults& other)
- : QValueList<KResolverEntry>(other), d(other.d)
+ : QValueList<KResolverEntry>(other), d(new KResolverResultsPrivate)
{
- d->ref();
+ *d = *other.d;
}
@@ -226,5 +213,4 @@ KResolverResults::KResolverResults(const
KResolverResults::~KResolverResults()
{
- if (d->deref())
delete d;
}
@@ -234,12 +220,9 @@ KResolverResults&
KResolverResults::operator= (const KResolverResults& other)
{
- other.d->ref();
-
- // release our data
- if (d->deref())
- delete d;
+ if (this == &other)
+ return *this;
// copy over the other data
- d = other.d;
+ *d = *other.d;
// now let QValueList do the rest of the work
@@ -264,6 +247,4 @@ int KResolverResults::systemError() cons
void KResolverResults::setError(int errorcode, int systemerror)
{
- d->dup(d);
-
d->errorcode = errorcode;
d->syserror = systemerror;
@@ -286,6 +267,4 @@ void KResolverResults::setAddress(const
const QString& service)
{
- d->dup(d);
-
d->node = node;
d->service = service;
@@ -875,5 +854,5 @@ QStrList KResolver::serviceName(int port
}
-#ifdef HAVE_GETSERVBYNAME_R
+#ifdef HAVE_GETSERVBYPORT_R
delete [] buf;
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic