Pass NewFunctionEvents as objects, not pointers
authorChristoph Egger <christoph@christoph-egger.org>
Tue, 2 Jun 2015 21:15:15 +0000 (23:15 +0200)
committerChristoph Egger <christoph@christoph-egger.org>
Tue, 2 Jun 2015 21:15:15 +0000 (23:15 +0200)
The current assumption -- emit will only return once all signal
handlers are done -- is false when cross-thread signals
happen. Therefore we can't assume the stack-allocated event is alive
long enough to just pass pointers. We're copying that object now which
should be pretty small and don't get any memory leaks or lifeness
problems.

src/core/InformationManager.cxx
src/core/InformationManager.hxx
src/gui/Mainwindow.cxx
src/gui/Mainwindow.hxx

index 4a48bae3c7070b12f0dbcd7551d28f9e88081fd0..500f79f1406f661c2a4ac53747fa053898ff0db6 100644 (file)
@@ -4,7 +4,6 @@
 #include "core/Function.hxx"
 #include "core/BasicBlock.hxx"
 #include "core/Comment.hxx"
-#include "core/events/NewFunctionEvent.hxx"
 #include "core/events/ChangeCommentEvent.hxx"
 
 #include "qt.hxx"
@@ -272,7 +271,7 @@ void InformationManager::finishFunction(Function* fun) {
                blocks.insert(std::make_pair(bl->getStartAddress(), bl));
        }
        NewFunctionEvent event(fun->getStartAddress(), fun);
-       emit newFunctionEvent(&event);
+       emit newFunctionEvent(event);
 }
 
 void InformationManager::finishBasicBlock(BasicBlock*) {
index c7d6321cdbf1e2c5386ae1983bc1c6022388b723..a866e0adf62c39791d8a8effe7453794f989cb60 100644 (file)
@@ -11,6 +11,8 @@
 #include "qt.hxx"
 #include "disassembler/Disassembler.hxx"
 
+#include "core/events/NewFunctionEvent.hxx"
+
 class Interpreter;
 
 class Function;
@@ -33,7 +35,7 @@ signals:
 public:
 #endif
        void renameFunctionEvent(RenameFunctionEvent* event);
-       void newFunctionEvent(NewFunctionEvent* event);
+       void newFunctionEvent(NewFunctionEvent event);
        void changeCommentEvent(ChangeCommentEvent* event);
        void resetEvent();
 public:
index 850c0364b61ba1c4d5fc845586ba8913fe48f9d9..1add669e55c6f32c3174f74e45123f71e746aa4c 100644 (file)
@@ -87,7 +87,7 @@ Mainwindow::Mainwindow(InformationManager* mgr)
 
        setWindowTitle(tr("FRIDA"));
 
-       QTreeWidgetItem * external = new QTreeWidgetItem(listWidget, QStringList("External Functions"));
+       external = new QTreeWidgetItem(listWidget, QStringList("External Functions"));
        external->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
        external->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd)));
        connect(mgr, &InformationManager::resetEvent,
@@ -96,15 +96,7 @@ Mainwindow::Mainwindow(InformationManager* mgr)
                                mgr->getDisassembler(), SLOT(disassembleFunctionAt(uint64_t)));
                });
        connect(mgr, &InformationManager::newFunctionEvent,
-               [=] (NewFunctionEvent* event) {
-                       std::string name = event->function->getName();
-                       if (event->function->isDynamic()) {
-                               auto item = new QTreeWidgetItem(external, QStringList(name.c_str()));
-                               item->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd)));
-                       } else {
-                               addFunction(event->function);
-                       }
-               });
+               this, &Mainwindow::handleNewFunctionEvent);
        connect(mgr, &InformationManager::renameFunctionEvent,
                [&](RenameFunctionEvent* event) {
                        if (objects_list_by_address.find(event->address) == objects_list_by_address.end())
@@ -126,6 +118,16 @@ void Mainwindow::setGlobalHotkeys() {
                });
 }
 
+void Mainwindow::handleNewFunctionEvent(NewFunctionEvent event) {
+       std::string name = event.function->getName();
+       if (event.function->isDynamic()) {
+               auto item = new QTreeWidgetItem(external, QStringList(name.c_str()));
+               item->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd)));
+       } else {
+               addFunction(event.function);
+       }
+}
+
 void Mainwindow::quit()
 {
        QMessageBox messageBox;
index 3a3a94d3b2388377ea5de3317924fe7cca6f02c9..769ba6f0dd8bcb1a9a43ed4628cb6650985e2bba 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <log4cxx/logger.h>
 
+#include "core/events/NewFunctionEvent.hxx"
+
 class Disassembler;
 class Function;
 class InformationManager;
@@ -46,6 +48,8 @@ private:
        QDockWidget * dockWidget;
        FridaDock * fdock;
 
+       QTreeWidgetItem * external;
+
        QAction *exitAction;
        QAction *openAction;
        QAction *loadAction;
@@ -71,6 +75,8 @@ private slots:
        void requestNewGroup();
        void renameFunction(Function* function);
        void renameGroup(QTreeWidgetItem* item);
+
+       void handleNewFunctionEvent(NewFunctionEvent event);
 };
 
 #endif /* INCLUDE__Mainwindow_hxx_ */