# # # patch "guitone/src/util/MemoryTrack.cpp" # from [428fd86704e8bd73537f5d6fc8664af3d53e1734] # to [c4b630ed0cc71ebee12dec3c83817fc811c78502] # # patch "guitone/src/util/MemoryTrack.h" # from [d4af041b9395deea89a017e87e1ea62e37fd9b0b] # to [0363b5b7bf27a144cb57dfc61a4aafd4a504b509] # # patch "guitone/src/view/MainWindow.cpp" # from [15c65a123a0b4defd361cd8884c5eb85ecf95b3b] # to [5bb992fcf91e28ec783cddafcf22a845c5828530] # ============================================================ --- guitone/src/util/MemoryTrack.cpp 428fd86704e8bd73537f5d6fc8664af3d53e1734 +++ guitone/src/util/MemoryTrack.cpp c4b630ed0cc71ebee12dec3c83817fc811c78502 @@ -64,17 +64,9 @@ bool mtPopStack() bool mtPopStack() { - if(mtTrackStack.isEmpty()) - { - qCritical("Tried to pop emtry memory track stack!!"); - return false; - } - else - { - mtWriteUnfreedCurrent(); - mtCurrentStackInfo = mtTrackStack.pop(); - return true; - } + mtWriteUnfreedCurrent(); + mtCurrentStackInfo = mtTrackStack.pop(); + return true; } @@ -113,12 +105,20 @@ void mtWriteUnfreed() void mtWriteUnfreed() { - mtWriteUnfreedCurrent(); - while (!mtTrackStack.isEmpty()) + if(!mtTrackStack.isEmpty()) { - mtCurrentStackInfo = mtTrackStack.pop(); + qCritical("Memory Track Stack is not emptry: there are open contexts!"); mtWriteUnfreedCurrent(); + while (!mtTrackStack.isEmpty()) + { + mtCurrentStackInfo = mtTrackStack.pop(); + mtWriteUnfreedCurrent(); + } } + else + { + mtWriteUnfreedCurrent(); + } } void mtWriteUnfreedCurrent() ============================================================ --- guitone/src/util/MemoryTrack.h d4af041b9395deea89a017e87e1ea62e37fd9b0b +++ guitone/src/util/MemoryTrack.h 0363b5b7bf27a144cb57dfc61a4aafd4a504b509 @@ -27,14 +27,23 @@ You can call mtnew(T, ...) to get a new tracked object. Deletes are tracked automatically by overloading operator delete. - You can start a new memory context by "mtpush {". To leave the context - you call "} mtpop;". + You can start a new memory context by mtpush(). To leave the context + you call mtpop(). The contexts are exception safe. But you can only + use it within the same block (within { }). + Example: + void test() + { + mtpush(); + mtnew(QString, "hello"); + mtpop(); + } + new QString("Hello") -> mtnew(QString, "Hello"); mtnew(): Create tracked object - mtpush {: Enter new memory context - } mtpop;: Leave memory context + mtpush() : Enter new memory context + mtpop() : Leave memory context */ // Disable memory contexts here @@ -63,18 +72,24 @@ bool mtPopStack(); void mtPushStack(const char *file, int line); bool mtPopStack(); +struct MTExceptionSafeContext +{ + inline MTExceptionSafeContext(const char *file, int line) { mtPushStack(file, line); } + inline ~MTExceptionSafeContext() { mtPopStack(); } +}; + class MTObjectDestroyNotify : public QObject { Q_OBJECT public: - void connectDestroy(QObject* obj) + inline void connectDestroy(QObject* obj) { connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*))); } private slots: - void objectDestroyed(QObject* obj) + inline void objectDestroyed(QObject* obj) { mtTrackDelete(obj); } @@ -92,8 +107,8 @@ private slots: #define mtpush void #define mtpop void #else //MT_NOCONTEXTS -#define mtpush mtPushStack(__FILE__, __LINE__); -#define mtpop mtPopStack(); +#define mtpush() { MTExceptionSafeContext dkeitngnvjfeks(__FILE__, __LINE__); +#define mtpop() } #endif //MT_NOCONTEXTS #ifdef _MT_VAARGSHACK @@ -116,8 +131,8 @@ inline void operator delete(void *ptr) #ifndef MEMORYTRACK_CPP #define mtWriteUnfreed void -#define mtpush void(); -#define mtpop void(); +#define mtpush void +#define mtpop void #define mtnew(type, ...) new type(__VA_ARGS__) #endif //MEMORYTRACK_CPP ============================================================ --- guitone/src/view/MainWindow.cpp 15c65a123a0b4defd361cd8884c5eb85ecf95b3b +++ guitone/src/view/MainWindow.cpp 5bb992fcf91e28ec783cddafcf22a845c5828530 @@ -458,42 +458,42 @@ void MainWindow::on_actionSwitch_revisio // TODO: connect Inventory with the accept() signal here somehow // before this works, we obviously need a separate update command // wrapper which signals us that we can re-read the inventory... - mtpush { - SwitchWorkspaceRevision dialog(this); - dialog.execDocumentModal(); - } mtpop; + mtpush(); + SwitchWorkspaceRevision dialog(this); + dialog.execDocumentModal(); + mtpop(); } void MainWindow::on_actionPreferences_triggered() { - mtpush { - Preferences dialog(this); - dialog.exec(); - } mtpop; + mtpush(); + Preferences dialog(this); + dialog.exec(); + mtpop(); } void MainWindow::on_actionKey_management_triggered() { - mtpush { - KeyManagement dialog(this); - dialog.execDocumentModal(); - } mtpop; + mtpush(); + KeyManagement dialog(this); + dialog.execDocumentModal(); + mtpop(); } void MainWindow:: on_actionChangeset_browser_triggered() { - mtpush { - DatabaseView dialog(this); - dialog.execDocumentModal(); - } mtpop; + mtpush(); + DatabaseView dialog(this); + dialog.execDocumentModal(); + mtpop(); } void MainWindow::on_actionAbout_guitone_triggered() { - mtpush { - About dialog(this); - dialog.exec(); - } mtpop; + mtpush(); + About dialog(this); + dialog.exec(); + mtpop(); } void MainWindow::on_actionAbout_Qt_triggered()