Skip to content

Commit 4832f69

Browse files
committed
b-173 Fixed memory leaks.
1 parent 8711fce commit 4832f69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+459
-354
lines changed

BRANCHES

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ devel
44

55
Branches:
66
---------
7-
172 - Fixes after code review.
8-
171 - Function key help.
7+
173 - Fixes after code review.
98

109
Merged branches:
1110
-------------
1211
172 - Allow configuration to qmake via command line
12+
171 - Function key help.
1313
170 - Search a command by name.
1414
169-UI-improvements - increasing user-friendliness
1515
issue-48 improve xsd display performance

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
0.9.11
2+
Fixed memory leaks.
3+
Issue #51 removed false error message.
24
Fixed a problem with prefixes manipulation and text nodes.
35
New panel to show keyboard shortcuts.
46
Added shortcuts to the guided operations dialog.

TODO

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Check issues:
55
TODO:
66
----
77

8-
#new is:171
9-
- menu contest. goto reference for elements and attributes
8+
9+
#new is:173
10+
- menu context. goto reference for elements and attributes
1011
- no attributes mode
1112

1213
164 - calculation of size of attributes, including filters

src/applicationdata.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ ApplicationData::~ApplicationData()
9999
}
100100
disconnect(&_sessionManager, SIGNAL(sessionActivated(const int)), this, SLOT(onSessionActivated(const int)));
101101
disconnect(&_sessionManager, SIGNAL(clearSession()), this, SLOT(onClearSession()));
102+
foreach(MainWindow * window, _windows) {
103+
window->forgetData();
104+
}
102105
}
103106

104107

@@ -176,7 +179,7 @@ int ApplicationData::windowsCount()
176179

177180
MainWindow *ApplicationData::newWindow()
178181
{
179-
MainWindow *mainWindow = new MainWindow(false, this);
182+
MainWindow *mainWindow = MainWindow::newDynamicTopLevelNewWindow(this);
180183
mainWindow->reposFrame();
181184
return mainWindow ;
182185
}

src/element.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -1172,11 +1172,7 @@ bool Element::isEmpty() const
11721172

11731173
void Element::clearAttributes()
11741174
{
1175-
QVectorIterator<Attribute*> it(attributes);
1176-
while(it.hasNext()) {
1177-
delete it.next();
1178-
}
1179-
attributes.clear();
1175+
EMPTYPTRLIST(attributes, Attribute);
11801176
}
11811177

11821178
bool Element::addAttribute(const QString &name, const QString &value)
@@ -2670,7 +2666,7 @@ bool Element::pasteClearAttributes(QList<Attribute*> &newAttributes, UndoPasteAt
26702666
Attribute * attribute = attributes.at(i);
26712667
if(attribute == attributeToDelete) {
26722668
attributes.remove(i);
2673-
delete attributeToDelete;
2669+
delete attribute;
26742670
isModified = true ;
26752671
break;
26762672
}
@@ -2724,6 +2720,7 @@ bool Element::removeAttribute(const QString &name)
27242720
if(attribute->name == name) {
27252721
int index = attributes.indexOf(attribute);
27262722
if(index >= 0) {
2723+
delete attributes.at(index);
27272724
attributes.remove(index);
27282725
return true;
27292726
}

src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ bool handleCommandLineArguments(QXmlEditApplication &app, StartParams &startPara
167167
default:
168168
break;
169169
case StartParams::VisFile: {
170-
MainWindow *mainWindow = new MainWindow(false, app.appData());
170+
MainWindow *mainWindow = MainWindow::newDynamicTopLevelNewWindow(app.appData());
171171
mainWindow->show();
172172
mainWindow->loadVisFile(startParams.fileName);
173173
handled = true ;

src/mainwindow.cpp

+28-20
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,16 @@ void ShowTextInDialoog(QWidget *parent, const QString &text);
9393
const QString MainWindow::ActionTagLastFiles("LastFiles");
9494
const QString MainWindow::ActionTagLastFolders("LastFolders");
9595

96-
MainWindow::MainWindow(const bool setIsSlave, ApplicationData *newData, QMainWindow *parent)
96+
MainWindow::MainWindow(const bool isAutoDelete, const bool setIsSlave, ApplicationData *newData, QMainWindow *parent)
9797
: QMainWindow(parent),
9898
_uiServices(this),
9999
data(newData),
100100
uiDelegate(this),
101101
_windowIcon(":/icon/images/icon.png"),
102102
_closing(false)
103103
{
104+
_isAutoDelete = isAutoDelete;
105+
isDeleted = false ;
104106
_infoOnEditMode = NULL ;
105107
_infoOnKeyboardShortcuts = NULL ;
106108
_scxmlValidationErrors = NULL ;
@@ -162,6 +164,7 @@ MainWindow::MainWindow(const bool setIsSlave, ApplicationData *newData, QMainWin
162164

163165
MainWindow::~MainWindow()
164166
{
167+
isDeleted = true ;
165168
ui.sessionTree->setSessionManager(NULL);
166169
dismissInfoOnKeyboard();
167170
dismissInfoEditTypes();
@@ -176,6 +179,7 @@ MainWindow::~MainWindow()
176179
void MainWindow::forgetData()
177180
{
178181
if(NULL != data) {
182+
ui.sessionTree->setSessionManager(NULL);
179183
disconnect(data, SIGNAL(clipboardDataChanged(bool)), this, SLOT(onClipboardDataChanged(bool)));
180184
disconnect(data, SIGNAL(stateKeyboardShortcutChanged(bool)), this, SLOT(onStateKeyboardShortcutChanged(bool)));
181185
if(!isSlave) {
@@ -194,7 +198,7 @@ ApplicationData *MainWindow::appData()
194198
QString MainWindow::editNodeElementAsXML(const bool isBase64Coded, Element *pElement, const QString & /*text*/, const bool /*isCData*/, bool &isCDataOut, bool &isOk)
195199
{
196200
QString result;
197-
MainWindow *mainWindow = new MainWindow(true, data, this) ;
201+
MainWindow *mainWindow = new MainWindow(true, true, data, this) ;
198202
mainWindow->setWindowModality(Qt::WindowModal);
199203
mainWindow->ui.editor->loadText(pElement->getAsSimpleText(isBase64Coded));
200204
mainWindow->ui.editor->setCDATA(pElement->isCDATA());
@@ -253,22 +257,12 @@ bool MainWindow::event(QEvent *e)
253257
const bool result = QMainWindow::event(e);
254258
switch(e->type()) {
255259
case QEvent::WindowActivate:
256-
#ifdef QXMLEDIT_TEST
257-
if(NULL == data) {
258-
qFatal("fault activation");
259-
}
260-
#endif
261-
if(NULL != data) {
260+
if((NULL != data) && !isDeleted) {
262261
data->newWindowActivationStatus(this, true);
263262
}
264263
break;
265264
case QEvent::WindowDeactivate:
266-
#ifdef QXMLEDIT_TEST
267-
if(NULL == data) {
268-
qFatal("fault deactivation");
269-
}
270-
#endif
271-
if(NULL != data) {
265+
if((NULL != data) && !isDeleted) {
272266
data->newWindowActivationStatus(this, false);
273267
}
274268
break;
@@ -1401,9 +1395,10 @@ void MainWindow::closeEvent(QCloseEvent * event)
14011395
if(!isSlave) {
14021396
// disable events until destroyed
14031397
forgetData();
1404-
deleteLater();
1398+
if(_isAutoDelete) {
1399+
deleteLater();
1400+
}
14051401
} else {
1406-
Utils::TODO_THIS_RELEASE("ma perche'? non forget data se closed? o deleted?");
14071402
_slaveIsClosed = true ;
14081403
if(NULL != eventLoop) {
14091404
eventLoop->exit(_returnCodeAsSlave);
@@ -2729,12 +2724,25 @@ void MainWindow::reposFrame()
27292724

27302725
MainWindow *MainWindow::makeNewWindow()
27312726
{
2732-
MainWindow *newWindow = new MainWindow(false, data);
2733-
if(NULL != newWindow) {
2734-
reposFrame();
27352727
#ifndef QXMLEDIT_TEST
2736-
newWindow->show();
2728+
const bool show = true ;
2729+
#else
2730+
const bool show = false ;
27372731
#endif
2732+
MainWindow *newWindow = MainWindow::newDynamicTopLevelNewWindow(data, true, show);
2733+
return newWindow;
2734+
}
2735+
2736+
MainWindow *MainWindow::newDynamicTopLevelNewWindow(ApplicationData *appData, const bool isRepos, const bool isShow)
2737+
{
2738+
MainWindow *newWindow = new MainWindow(true, false, appData);
2739+
if(NULL != newWindow) {
2740+
if(isRepos) {
2741+
newWindow->reposFrame();
2742+
}
2743+
if(isShow) {
2744+
newWindow->show();
2745+
}
27382746
} else {
27392747
Utils::error(tr("Error opening a new window."));
27402748
}

src/mainwindow.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class MainWindow : public QMainWindow, UIDelegate, XMLLoadErrorHandler
5353

5454
static const uint MaxTimesElementEditedWithoutText = 10 ;
5555

56+
bool isDeleted;
5657
bool started;
5758
bool internalStateOk;
5859
MainWndController _controller;
@@ -93,6 +94,7 @@ class MainWindow : public QMainWindow, UIDelegate, XMLLoadErrorHandler
9394
bool _closing ;
9495
InfoOnKeyboardShortcuts * _infoOnKeyboardShortcuts;
9596
InfoOnEditMode *_infoOnEditMode;
97+
bool _isAutoDelete ;
9698
public:
9799

98100
//---------- actions -------------------
@@ -106,9 +108,11 @@ class MainWindow : public QMainWindow, UIDelegate, XMLLoadErrorHandler
106108
OpenUsingNewWindow,
107109
};
108110

109-
MainWindow(const bool isSlave, ApplicationData *data, QMainWindow *parent = 0);
111+
MainWindow(const bool isAutodelete, const bool isSlave, ApplicationData *data, QMainWindow *parent = 0);
110112
virtual ~MainWindow();
111113

114+
static MainWindow *newDynamicTopLevelNewWindow(ApplicationData *data, const bool isRepos = true, const bool isShow = true);
115+
112116
ApplicationData *appData();
113117
virtual bool loadFile(const QString &filePath, const bool activateModes = true, const EWindowOpen useWindow = OpenUsingDefaultSettings, const bool isRegularFile = true);
114118
MainWindow *loadFileAndReturnWindow(const QString &filePath, const bool activateModes = true,
@@ -170,9 +174,9 @@ class MainWindow : public QMainWindow, UIDelegate, XMLLoadErrorHandler
170174
bool isValidXsd();
171175
void viewAsXSD();
172176
void fireActionByName(const QString &name);
177+
void forgetData();
173178

174179
protected:
175-
void forgetData();
176180
virtual void changeEvent(QEvent *event);
177181
virtual bool event(QEvent *e);
178182
void dismissInfoOnKeyboard();

src/modules/compare/diffresult.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ DiffSingleNodeResult::~DiffSingleNodeResult()
102102
foreach(DiffSingleNodeResult * child, _children) {
103103
delete child ;
104104
}
105+
if(NULL != _referenceElement) {
106+
delete _referenceElement ;
107+
}
108+
if(NULL != _compareElement) {
109+
delete _compareElement ;
110+
}
105111
}
106112

107113
QList<Attribute*> &DiffSingleNodeResult::equalsAttributes()

src/modules/namespace/elementnamespace.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ bool Element::removeNamespace(const QString &removedNS, TargetSelection::Type ta
240240
changed = true ;
241241
attrChanged = true ;
242242
foreach(int index, deleteIndexes) {
243+
// already deleted
243244
attributes.remove(index);
244245
}
245246
}
@@ -379,12 +380,14 @@ bool Element::normalizeNamespace(const QString &theNS, const QString &thePrefix,
379380
XmlUtils::getNsPrefix(attr->name, prefix);
380381
if((prefix != thePrefix) && (attr->value == theNS)) {
381382
attrIterator.remove();
383+
delete attr;
382384
attrChanged = true;
383385
} else {
384386
if((prefix == thePrefix) && (attr->value == theNS)) {
385387
existsDeclaration = true;
386388
if(!isRoot && declareOnlyOnRoot) {
387389
//remove this declaration, declarations are legal only on root
390+
delete attr;
388391
attrIterator.remove();
389392
attrChanged = true;
390393
} else {

src/modules/services/colorentry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "qxmleditconfig.h"
2626
#include "utils.h"
2727

28-
ColorEntry::ColorEntry(const QString &newKey, const QColor newDefaultValue)
28+
ColorEntry::ColorEntry(const QString &newKey, const QColor newDefaultValue) : _color(0, 0, 0)
2929
{
3030
_key = newKey ;
3131
_isSet = false;

src/qxmleditapplication.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ void QXmlEditApplication::setupFirstAccessForPreferences()
513513
MainWindow *QXmlEditApplication::getOrCreateMainWindow()
514514
{
515515
if(appData()->windows().isEmpty()) {
516-
MainWindow *mainWindow = new MainWindow(false, _appData);
516+
MainWindow *mainWindow = MainWindow::newDynamicTopLevelNewWindow(_appData, true, false);
517517
return mainWindow ;
518518
}
519519
return appData()->windows().at(0);

src/qxmleditapplicationcommands.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
void QXmlEditApplication::onCommandNew()
4242
{
43-
MainWindow *mainWindow = new MainWindow(false, _appData);
43+
MainWindow *mainWindow = MainWindow::newDynamicTopLevelNewWindow(_appData);
4444
mainWindow->show();
4545
mainWindow->raise();
4646
mainWindow->activateWindow();
@@ -60,7 +60,7 @@ void QXmlEditApplication::onCommandQuit()
6060

6161
void QXmlEditApplication::onCommandOpen()
6262
{
63-
MainWindow *mainWindow = new MainWindow(false, _appData);
63+
MainWindow *mainWindow = MainWindow::newDynamicTopLevelNewWindow(_appData, true, false);
6464
if(mainWindow->openFileUsingDialog(QXmlEditData::sysFilePathForOperation(""), MainWindow::OpenUsingSameWindow)) {
6565
mainWindow->show();
6666
mainWindow->raise();
@@ -162,7 +162,7 @@ void QXmlEditApplication::onCommandViewXMLMap()
162162

163163
void QXmlEditApplication::onCommandOpenFile(const QString &filePath)
164164
{
165-
MainWindow *mainWindow = new MainWindow(false, _appData);
165+
MainWindow *mainWindow = MainWindow::newDynamicTopLevelNewWindow(_appData, true, false);
166166
if(mainWindow->loadFile(filePath, MainWindow::OpenUsingSameWindow)) {
167167
mainWindow->show();
168168
mainWindow->raise();

src/sessions/sessiondrawerwidgetprivate.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void SessionDrawerWidgetPrivate::disconnectSessionManager()
6363
disconnect(_sessionManager, SIGNAL(sessionStateChanged(Session::SessionState)), this, SLOT(onSessionStateChanged(Session::SessionState)));
6464
disconnect(_sessionManager, SIGNAL(dataChanged()), this, SLOT(onSessionDataChanged()));
6565
disconnect(_sessionManager, SIGNAL(enablingChanged()), this, SLOT(onEnablingChanged()));
66+
_sessionManager = NULL ;
6667
}
6768
}
6869

src/xsdeditor/XSchemaCollectionUtilities.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ XSchemaAttributesCollection::XSchemaAttributesCollection()
5959

6060
XSchemaAttributesCollection::~XSchemaAttributesCollection()
6161
{
62-
foreach(QString name, attributes.keys()) {
63-
AttrCollectInfo* attr = attributes[name];
62+
foreach(AttrCollectInfo* attr, attributes.values()) {
6463
delete attr;
6564
}
6665
attributes.clear();
@@ -74,6 +73,10 @@ void XSchemaAttributesCollection::insert(const QString &name, XSchemaAttribute*
7473
info->enums = parEnums;
7574
info->defaultValue = defaultValue ;
7675
info->originalAttribute = originalAttribute ;
76+
if(attributes.contains(name)) {
77+
delete attributes[name];
78+
attributes.remove(name);
79+
}
7780
attributes.insert(name, info);
7881
}
7982

src/xsdeditor/io/xschemaloaderhelper.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
* Boston, MA 02110-1301 USA *
2121
**************************************************************************/
2222

23-
23+
#include "xmlEdit.h"
2424
#include "xschemaloaderhelper.h"
25+
#include "utils.h"
2526

2627
XSchemaLoaderHelper::XSchemaLoaderHelper(QObject *parent) :
2728
QObject(parent)
@@ -41,6 +42,8 @@ XSchemaLoaderHelper::~XSchemaLoaderHelper()
4142
void XSchemaLoaderHelper::abort()
4243
{
4344
if(NULL != _networkReply) {
45+
Utils::TODO_THIS_RELEASE("corretto?");
46+
disconnectReply();
4447
_networkReply->abort();
4548
_networkReply->deleteLater();
4649
_networkReply = NULL ;
@@ -51,7 +54,9 @@ QNetworkReply* XSchemaLoaderHelper::loadSchemaUsingUrl(QUrl &url, QNetworkAccess
5154
{
5255
_isAsynch = asynch ;
5356
_isError = false;
54-
_networkReply = networkAccessManager->get(QNetworkRequest(url));
57+
_request.setUrl(url);
58+
Utils::TODO_THIS_RELEASE("");
59+
_networkReply = networkAccessManager->get(_request);
5560
if(NULL == _networkReply) {
5661
return NULL ;
5762
}

src/xsdeditor/io/xschemaloaderhelper.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class XSchemaLoaderHelper : public QObject
3737
bool _isError ;
3838
QEventLoop _eventLoop;
3939
bool _isAsynch;
40+
QNetworkRequest _request;
4041

4142
void end();
4243
void disconnectReply();

0 commit comments

Comments
 (0)