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
Branches
Tags
No related merge requests found
......@@ -99,7 +99,7 @@ public:
bool m_SortAlphabetical ;
QString m_DefaultCategory ;
bool m_UnreachableHidden;
SortingCategory::ModelTuple* m_pSortedProxy ;
SortingCategory::ModelTuple* m_pSortedProxy {nullptr};
CategorizedContactModel::SortedProxy m_pProxies ;
//Helper
......@@ -260,6 +260,9 @@ CategorizedContactModel::~CategorizedContactModel()
foreach(ContactTreeNode* item,d_ptr->m_lCategoryCounter) {
delete item;
}
if (d_ptr->m_pSortedProxy)
delete d_ptr->m_pSortedProxy;
}
CategorizedContactModel& CategorizedContactModel::instance()
......
......@@ -62,7 +62,7 @@ public:
QVector<HistoryNode*> m_lCategoryCounter ;
QHash<int,HistoryNode*> m_hCategories ;
QHash<QString,HistoryNode*> m_hCategoryByName ;
SortingCategory::ModelTuple* m_pSortedProxy ;
SortingCategory::ModelTuple* m_pSortedProxy {nullptr};
int m_Role ;
QStringList m_lMimes ;
CategorizedHistoryModel::SortedProxy m_pProxies;
......@@ -128,6 +128,9 @@ CategorizedHistoryModel::~CategorizedHistoryModel()
delete item;
}
if (d_ptr->m_pSortedProxy)
delete d_ptr->m_pSortedProxy;
}
QHash<int,QByteArray> CategorizedHistoryModel::roleNames() const
......
......@@ -80,6 +80,8 @@ void CollectionInterface::init()
///Destructor
CollectionInterface::~CollectionInterface()
{
d_ptr->m_fDestruct();
delete d_ptr2;
delete d_ptr;
}
......
......@@ -42,10 +42,14 @@ public:
std::function<bool(ItemBase*)> m_fEdit ;
std::function<bool(ItemBase*)> m_fRemove ;
std::function<int() > m_fSize ;
std::function<void() > m_fDestruct ;
std::function<CollectionConfigurationInterface*()> m_fConfigurator;
};
/**
* The collection from now on take ownership of the editor
*/
template<typename T>
CollectionInterface::CollectionInterface(CollectionEditor<T>* editor, CollectionInterface* parent) :
d_ptr(new CollectionInterfacePrivateT())
......@@ -72,6 +76,9 @@ d_ptr(new CollectionInterfacePrivateT())
d_ptr->m_fSize = [editor]()->int {
return editor?editor->items().size() : 0;
};
d_ptr->m_fDestruct = [editor]() {
delete editor;
};
}
template<typename T>
......
......@@ -39,6 +39,7 @@ template<typename T>
class LIB_EXPORT CollectionMediator {
public:
CollectionMediator(CollectionManagerInterface<T>* parentManager, QAbstractItemModel* m);
virtual ~CollectionMediator();
bool addItem (const T* item);
bool removeItem(const T* item);
......
......@@ -34,6 +34,12 @@ CollectionMediator<T>::CollectionMediator(CollectionManagerInterface<T>* parentM
d_ptr->m_pModel = m;
}
template<typename T>
CollectionMediator<T>::~CollectionMediator()
{
delete d_ptr;
}
template<typename T>
bool CollectionMediator<T>::addItem(const T* item)
{
......
......@@ -42,6 +42,17 @@ CollectionModelPrivate::CollectionModelPrivate(CollectionModel* parent) : QObjec
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))
{
load();
......
......@@ -80,7 +80,7 @@ public:
constexpr const char LocalBookmarkCollectionPrivate::FILENAME[];
LocalBookmarkCollection::LocalBookmarkCollection(CollectionMediator<ContactMethod>* mediator) :
CollectionInterface(new LocalBookmarkEditor(mediator))
CollectionInterface(new LocalBookmarkEditor(mediator)), d_ptr(new LocalBookmarkCollectionPrivate())
{
load();
}
......
......@@ -31,8 +31,9 @@
//DRing
#include "dbus/configurationmanager.h"
struct RecordingNode
struct RecordingNode final
{
~RecordingNode();
enum class Type {
TOP_LEVEL,
......@@ -52,16 +53,17 @@ struct RecordingNode
};
class RecordingModelPrivate : public QObject
class RecordingModelPrivate final : public QObject
{
Q_OBJECT
public:
RecordingModelPrivate(Media::RecordingModel* parent);
explicit RecordingModelPrivate(Media::RecordingModel* parent);
~RecordingModelPrivate();
//Attributes
QVector<RecordingNode*> m_lCategories ;
RecordingNode* m_pText ;
RecordingNode* m_pAudioVideo ;
RecordingNode* m_pText {nullptr};
RecordingNode* m_pAudioVideo {nullptr};
LocalTextRecordingCollection* m_pTextRecordingCollection;
int m_UnreadCount ;
......@@ -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),
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)
{
Q_UNUSED(message)
......
......@@ -41,9 +41,11 @@
#include "media/textrecording.h"
#include "mime.h"
class AddressPrivate
class AddressPrivate final
{
public:
~AddressPrivate() {}
QString addressLine;
QString city;
QString zipCode;
......@@ -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
{
return d_ptr->addressLine;
......
......@@ -69,7 +69,8 @@ public:
///Represent the physical address of a contact
class Address {
public:
Address();
explicit Address();
virtual ~Address();
//Getters
QString addressLine() const;
......
......@@ -35,7 +35,8 @@ class CollectionModelPrivate final : public QObject
{
Q_OBJECT
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
......@@ -44,6 +45,7 @@ public:
*/
struct ProxyItem {
ProxyItem() : parent(nullptr),col(0),row(0),collection(nullptr),manageableCount(0){}
virtual ~ProxyItem();
int row;
int col;
CollectionInterface* collection;
......
......@@ -124,6 +124,8 @@ struct Node final
virtual ~Node() {
QObject::disconnect(m_ChangedConn);
foreach( Node* n, children)
delete n;
}
enum class Type : bool {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment