Skip to content
Snippets Groups Projects
Commit a735b5e5 authored by Emmanuel Lepage Vallée's avatar Emmanuel Lepage Vallée Committed by Stepan Salenikovich
Browse files

quality: Fix memory leaks

There is still some, but most are fixed.

The Person::Address::d_ptr leak a lot of memory. Fixing it
trigger something in ASAN and assert, this need investigation.

Change-Id: I98b4f18cac7f36a5878f5be6ca17c672d6a3fc72
Tuleap: #414
parent bed13016
No related branches found
No related tags found
No related merge requests found
...@@ -99,7 +99,7 @@ public: ...@@ -99,7 +99,7 @@ public:
bool m_SortAlphabetical ; bool m_SortAlphabetical ;
QString m_DefaultCategory ; QString m_DefaultCategory ;
bool m_UnreachableHidden; bool m_UnreachableHidden;
SortingCategory::ModelTuple* m_pSortedProxy ; SortingCategory::ModelTuple* m_pSortedProxy {nullptr};
CategorizedContactModel::SortedProxy m_pProxies ; CategorizedContactModel::SortedProxy m_pProxies ;
//Helper //Helper
...@@ -260,6 +260,9 @@ CategorizedContactModel::~CategorizedContactModel() ...@@ -260,6 +260,9 @@ CategorizedContactModel::~CategorizedContactModel()
foreach(ContactTreeNode* item,d_ptr->m_lCategoryCounter) { foreach(ContactTreeNode* item,d_ptr->m_lCategoryCounter) {
delete item; delete item;
} }
if (d_ptr->m_pSortedProxy)
delete d_ptr->m_pSortedProxy;
} }
CategorizedContactModel& CategorizedContactModel::instance() CategorizedContactModel& CategorizedContactModel::instance()
......
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
QVector<HistoryNode*> m_lCategoryCounter ; QVector<HistoryNode*> m_lCategoryCounter ;
QHash<int,HistoryNode*> m_hCategories ; QHash<int,HistoryNode*> m_hCategories ;
QHash<QString,HistoryNode*> m_hCategoryByName ; QHash<QString,HistoryNode*> m_hCategoryByName ;
SortingCategory::ModelTuple* m_pSortedProxy ; SortingCategory::ModelTuple* m_pSortedProxy {nullptr};
int m_Role ; int m_Role ;
QStringList m_lMimes ; QStringList m_lMimes ;
CategorizedHistoryModel::SortedProxy m_pProxies; CategorizedHistoryModel::SortedProxy m_pProxies;
...@@ -128,6 +128,9 @@ CategorizedHistoryModel::~CategorizedHistoryModel() ...@@ -128,6 +128,9 @@ CategorizedHistoryModel::~CategorizedHistoryModel()
delete item; delete item;
} }
if (d_ptr->m_pSortedProxy)
delete d_ptr->m_pSortedProxy;
} }
QHash<int,QByteArray> CategorizedHistoryModel::roleNames() const QHash<int,QByteArray> CategorizedHistoryModel::roleNames() const
......
...@@ -80,6 +80,8 @@ void CollectionInterface::init() ...@@ -80,6 +80,8 @@ void CollectionInterface::init()
///Destructor ///Destructor
CollectionInterface::~CollectionInterface() CollectionInterface::~CollectionInterface()
{ {
d_ptr->m_fDestruct();
delete d_ptr2;
delete d_ptr; delete d_ptr;
} }
......
...@@ -42,10 +42,14 @@ public: ...@@ -42,10 +42,14 @@ public:
std::function<bool(ItemBase*)> m_fEdit ; std::function<bool(ItemBase*)> m_fEdit ;
std::function<bool(ItemBase*)> m_fRemove ; std::function<bool(ItemBase*)> m_fRemove ;
std::function<int() > m_fSize ; std::function<int() > m_fSize ;
std::function<void() > m_fDestruct ;
std::function<CollectionConfigurationInterface*()> m_fConfigurator; std::function<CollectionConfigurationInterface*()> m_fConfigurator;
}; };
/**
* The collection from now on take ownership of the editor
*/
template<typename T> template<typename T>
CollectionInterface::CollectionInterface(CollectionEditor<T>* editor, CollectionInterface* parent) : CollectionInterface::CollectionInterface(CollectionEditor<T>* editor, CollectionInterface* parent) :
d_ptr(new CollectionInterfacePrivateT()) d_ptr(new CollectionInterfacePrivateT())
...@@ -72,6 +76,9 @@ d_ptr(new CollectionInterfacePrivateT()) ...@@ -72,6 +76,9 @@ d_ptr(new CollectionInterfacePrivateT())
d_ptr->m_fSize = [editor]()->int { d_ptr->m_fSize = [editor]()->int {
return editor?editor->items().size() : 0; return editor?editor->items().size() : 0;
}; };
d_ptr->m_fDestruct = [editor]() {
delete editor;
};
} }
template<typename T> template<typename T>
......
...@@ -39,6 +39,7 @@ template<typename T> ...@@ -39,6 +39,7 @@ template<typename T>
class LIB_EXPORT CollectionMediator { class LIB_EXPORT CollectionMediator {
public: public:
CollectionMediator(CollectionManagerInterface<T>* parentManager, QAbstractItemModel* m); CollectionMediator(CollectionManagerInterface<T>* parentManager, QAbstractItemModel* m);
virtual ~CollectionMediator();
bool addItem (const T* item); bool addItem (const T* item);
bool removeItem(const T* item); bool removeItem(const T* item);
......
...@@ -34,6 +34,12 @@ CollectionMediator<T>::CollectionMediator(CollectionManagerInterface<T>* parentM ...@@ -34,6 +34,12 @@ CollectionMediator<T>::CollectionMediator(CollectionManagerInterface<T>* parentM
d_ptr->m_pModel = m; d_ptr->m_pModel = m;
} }
template<typename T>
CollectionMediator<T>::~CollectionMediator()
{
delete d_ptr;
}
template<typename T> template<typename T>
bool CollectionMediator<T>::addItem(const T* item) bool CollectionMediator<T>::addItem(const T* item)
{ {
......
...@@ -42,6 +42,17 @@ CollectionModelPrivate::CollectionModelPrivate(CollectionModel* parent) : QObjec ...@@ -42,6 +42,17 @@ CollectionModelPrivate::CollectionModelPrivate(CollectionModel* parent) : QObjec
m_pManageableProxy(nullptr),m_NewCollectionMutex(QMutex::Recursive) m_pManageableProxy(nullptr),m_NewCollectionMutex(QMutex::Recursive)
{} {}
CollectionModelPrivate::~CollectionModelPrivate()
{
}
CollectionModelPrivate::ProxyItem::~ProxyItem()
{
foreach(ProxyItem* i, m_Children)
delete i;
}
CollectionModel::CollectionModel(QObject* parent) : QAbstractTableModel(parent), d_ptr(new CollectionModelPrivate(this)) CollectionModel::CollectionModel(QObject* parent) : QAbstractTableModel(parent), d_ptr(new CollectionModelPrivate(this))
{ {
load(); load();
......
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
constexpr const char LocalBookmarkCollectionPrivate::FILENAME[]; constexpr const char LocalBookmarkCollectionPrivate::FILENAME[];
LocalBookmarkCollection::LocalBookmarkCollection(CollectionMediator<ContactMethod>* mediator) : LocalBookmarkCollection::LocalBookmarkCollection(CollectionMediator<ContactMethod>* mediator) :
CollectionInterface(new LocalBookmarkEditor(mediator)) CollectionInterface(new LocalBookmarkEditor(mediator)), d_ptr(new LocalBookmarkCollectionPrivate())
{ {
load(); load();
} }
......
...@@ -31,8 +31,9 @@ ...@@ -31,8 +31,9 @@
//DRing //DRing
#include "dbus/configurationmanager.h" #include "dbus/configurationmanager.h"
struct RecordingNode struct RecordingNode final
{ {
~RecordingNode();
enum class Type { enum class Type {
TOP_LEVEL, TOP_LEVEL,
...@@ -52,16 +53,17 @@ struct RecordingNode ...@@ -52,16 +53,17 @@ struct RecordingNode
}; };
class RecordingModelPrivate : public QObject class RecordingModelPrivate final : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
RecordingModelPrivate(Media::RecordingModel* parent); explicit RecordingModelPrivate(Media::RecordingModel* parent);
~RecordingModelPrivate();
//Attributes //Attributes
QVector<RecordingNode*> m_lCategories ; QVector<RecordingNode*> m_lCategories ;
RecordingNode* m_pText ; RecordingNode* m_pText {nullptr};
RecordingNode* m_pAudioVideo ; RecordingNode* m_pAudioVideo {nullptr};
LocalTextRecordingCollection* m_pTextRecordingCollection; LocalTextRecordingCollection* m_pTextRecordingCollection;
int m_UnreadCount ; int m_UnreadCount ;
...@@ -80,12 +82,30 @@ RecordingNode::RecordingNode(RecordingNode::Type type) : ...@@ -80,12 +82,30 @@ RecordingNode::RecordingNode(RecordingNode::Type type) :
} }
RecordingNode::~RecordingNode()
{
foreach(RecordingNode* c, m_lChildren)
delete c;
}
RecordingModelPrivate::RecordingModelPrivate(Media::RecordingModel* parent) : q_ptr(parent),m_pText(nullptr), RecordingModelPrivate::RecordingModelPrivate(Media::RecordingModel* parent) : q_ptr(parent),m_pText(nullptr),
m_pAudioVideo(nullptr)/*,m_pFiles(nullptr)*/ m_pAudioVideo(nullptr)/*,m_pFiles(nullptr)*/
{ {
} }
RecordingModelPrivate::~RecordingModelPrivate()
{
if (m_pTextRecordingCollection)
delete m_pTextRecordingCollection;
if (m_pText)
delete m_pText;
if (m_pAudioVideo)
delete m_pAudioVideo;
}
void RecordingModelPrivate::forwardInsertion(const QMap<QString,QString>& message, ContactMethod* cm, Media::Media::Direction direction) void RecordingModelPrivate::forwardInsertion(const QMap<QString,QString>& message, ContactMethod* cm, Media::Media::Direction direction)
{ {
Q_UNUSED(message) Q_UNUSED(message)
......
...@@ -41,9 +41,11 @@ ...@@ -41,9 +41,11 @@
#include "media/textrecording.h" #include "media/textrecording.h"
#include "mime.h" #include "mime.h"
class AddressPrivate class AddressPrivate final
{ {
public: public:
~AddressPrivate() {}
QString addressLine; QString addressLine;
QString city; QString city;
QString zipCode; QString zipCode;
...@@ -57,6 +59,11 @@ Person::Address::Address() : d_ptr(new AddressPrivate()) ...@@ -57,6 +59,11 @@ Person::Address::Address() : d_ptr(new AddressPrivate())
} }
Person::Address::~Address()
{
//delete d_ptr; //FIXME ASAN doesn't like for some reasons, but also report a leak
}
QString Person::Address::addressLine() const QString Person::Address::addressLine() const
{ {
return d_ptr->addressLine; return d_ptr->addressLine;
......
...@@ -69,7 +69,8 @@ public: ...@@ -69,7 +69,8 @@ public:
///Represent the physical address of a contact ///Represent the physical address of a contact
class Address { class Address {
public: public:
Address(); explicit Address();
virtual ~Address();
//Getters //Getters
QString addressLine() const; QString addressLine() const;
......
...@@ -35,7 +35,8 @@ class CollectionModelPrivate final : public QObject ...@@ -35,7 +35,8 @@ class CollectionModelPrivate final : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
CollectionModelPrivate(CollectionModel* parent); explicit CollectionModelPrivate(CollectionModel* parent);
virtual ~CollectionModelPrivate();
/* /*
* This is not very efficient, it doesn't really have to be given the low * This is not very efficient, it doesn't really have to be given the low
...@@ -44,6 +45,7 @@ public: ...@@ -44,6 +45,7 @@ public:
*/ */
struct ProxyItem { struct ProxyItem {
ProxyItem() : parent(nullptr),col(0),row(0),collection(nullptr),manageableCount(0){} ProxyItem() : parent(nullptr),col(0),row(0),collection(nullptr),manageableCount(0){}
virtual ~ProxyItem();
int row; int row;
int col; int col;
CollectionInterface* collection; CollectionInterface* collection;
......
...@@ -124,6 +124,8 @@ struct Node final ...@@ -124,6 +124,8 @@ struct Node final
virtual ~Node() { virtual ~Node() {
QObject::disconnect(m_ChangedConn); QObject::disconnect(m_ChangedConn);
foreach( Node* n, children)
delete n;
} }
enum class Type : bool { enum class Type : bool {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment