From: Christoph Egger Date: Tue, 2 Jun 2015 21:15:15 +0000 (+0200) Subject: Pass NewFunctionEvents as objects, not pointers X-Git-Url: https://git.siccegge.de//index.cgi?p=frida%2Ffrida.git;a=commitdiff_plain;h=f9d8bd4a0312a92a1ec3493e83996c0a99d8d1bf Pass NewFunctionEvents as objects, not pointers 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. --- diff --git a/src/core/InformationManager.cxx b/src/core/InformationManager.cxx index 4a48bae..500f79f 100644 --- a/src/core/InformationManager.cxx +++ b/src/core/InformationManager.cxx @@ -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*) { diff --git a/src/core/InformationManager.hxx b/src/core/InformationManager.hxx index c7d6321..a866e0a 100644 --- a/src/core/InformationManager.hxx +++ b/src/core/InformationManager.hxx @@ -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: diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 850c036..1add669 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -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; diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index 3a3a94d..769ba6f 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -14,6 +14,8 @@ #include +#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_ */