[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdelibs/kdecore/network
From:       Thiago Macieira <thiago.macieira () kdemail ! net>
Date:       2005-01-07 16:48:17
Message-ID: 20050107164817.008551BA8D () office ! kde ! org
[Download RAW message or body]

CVS commit by thiago: 

Fixing, once and for all, the memory leak. KResolverResults now no
longer implicitly shares the two ints and two QStrings it has on top
of QValueList (the list items continue to be shared).


  M +8 -29     kresolver.cpp   1.41


--- kdelibs/kdecore/network/kresolver.cpp  #1.40:1.41
@@ -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>
  *
  *
@@ -191,5 +191,5 @@ KResolverEntry& KResolverEntry::operator
 // class KResolverResults
 
-class KNetwork::KResolverResultsPrivate: public QShared
+class KNetwork::KResolverResultsPrivate
 {
 public:
@@ -200,17 +200,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
-      }
-  }
 };
 
@@ -223,7 +210,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;
 }
 
@@ -231,5 +218,4 @@ KResolverResults::KResolverResults(const
 KResolverResults::~KResolverResults()
 {
-  if (d->deref())
     delete d;
 }
@@ -239,12 +225,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
@@ -269,6 +252,4 @@ int KResolverResults::systemError() cons
 void KResolverResults::setError(int errorcode, int systemerror)
 {
-  d->dup(d);
-
   d->errorcode = errorcode;
   d->syserror = systemerror;
@@ -291,6 +272,4 @@ void KResolverResults::setAddress(const 
                                   const QString& service)
 {
-  d->dup(d);
-
   d->node = node;
   d->service = service;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic