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

List:       kde-commits
Subject:    [kcachegrind/frameworks] libcore: fix memleak found by Coverity. now calls like:
From:       Nick Shaforostoff <shafff () ukr ! net>
Date:       2016-03-18 22:18:28
Message-ID: E1ah2iy-00073r-C1 () scm ! kde ! org
[Download RAW message or body]

Git commit c1bb693005c2f3ded12e5df6a2fd4a5c6edda9c0 by Nick Shaforostoff.
Committed on 18/03/2016 at 22:16.
Pushed by shaforo into branch 'frameworks'.

fix memleak found by Coverity. now calls like:
if (!EventType::knownDerivedType(tr("New%1").arg(i)))
are fine

CCMAIL: Josef.Weidendorfer@gmx.de

M  +6    -7    libcore/eventtype.cpp

http://commits.kde.org/kcachegrind/c1bb693005c2f3ded12e5df6a2fd4a5c6edda9c0

diff --git a/libcore/eventtype.cpp b/libcore/eventtype.cpp
index ec56f8b..7ccc4e8 100644
--- a/libcore/eventtype.cpp
+++ b/libcore/eventtype.cpp
@@ -239,8 +239,7 @@ EventType* EventType::knownRealType(const QString& n)
 
   foreach (EventType* t, *_knownTypes)
     if (t->isReal() && (t->name() == n)) {
-      EventType* type = new EventType(*t);
-      return type;
+      return t;
     }
 
   return 0;
@@ -252,8 +251,7 @@ EventType* EventType::knownDerivedType(const QString& n)
 
   foreach (EventType* t, *_knownTypes)
     if (!t->isReal() && (t->name() == n)) {
-      EventType* type = new EventType(*t);
-      return type;
+      return t;
     }
 
   return 0;
@@ -332,10 +330,10 @@ EventTypeSet::EventTypeSet()
 EventTypeSet::~EventTypeSet()
 {
   for (int i=0;i<ProfileCostArray::MaxRealIndex;i++)
-    if (_real[i]) delete _real[i];
+    delete _real[i];
 
   for (int i=0;i<ProfileCostArray::MaxRealIndex;i++)
-    if (_derived[i]) delete _derived[i];
+    delete _derived[i];
 }
 
 EventTypeMapping* EventTypeSet::createMapping(const QString& types)
@@ -390,7 +388,8 @@ int EventTypeSet::addReal(const QString& t)
   if (index>=0) return index;
 
   EventType* ct = EventType::knownRealType(t);
-  if (!ct) ct = new EventType(t, t);
+  if (ct) ct = new EventType(*ct); //clone it
+  else    ct = new EventType(t, t);
 
   // make it real
   ct->setRealIndex();
[prev in list] [next in list] [prev in thread] [next in thread] 

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