Skip to content

Commit

Permalink
Fix null derefs when using r2 build without threads
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Feb 6, 2022
1 parent 4fee825 commit 28a1099
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/Iaito.pro
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ unix:QMAKE_RPATHDIR += /usr/local/lib
unix:QMAKE_LFLAGS_RPATH=
unix:QMAKE_LFLAGS += "-Wl,-rpath,/usr/local/lib"

# build with thread-sanitizer
# unix:QMAKE_LFLAGS += "-fsanitize=thread"
# QMAKE_CXXFLAGS += -fsanitize=thread
QMAKE_CXXFLAGS += -g


VERSION = $${IAITO_VERSION_MAJOR}.$${IAITO_VERSION_MINOR}.$${IAITO_VERSION_PATCH}

Expand Down
22 changes: 17 additions & 5 deletions src/common/R2Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ R2Task::R2Task(const QString &cmd, bool transient)
cmd.toLocal8Bit().constData(),
static_cast<RCoreTaskCallback>(&R2Task::taskFinishedCallback),
this);
task->transient = transient;
r_core_task_incref(task);
if (task) {
task->transient = transient;
r_core_task_incref(task);
}
}

R2Task::~R2Task()
Expand All @@ -34,25 +36,35 @@ void R2Task::startTask()

void R2Task::breakTask()
{
r_core_task_break(&Core()->core_->tasks, task->id);
if (task) {
r_core_task_break(&Core()->core_->tasks, task->id);
}
}

void R2Task::joinTask()
{
r_core_task_join(&Core()->core_->tasks, nullptr, task->id);
if (task) {
r_core_task_join(&Core()->core_->tasks, nullptr, task->id);
}
}

QString R2Task::getResult()
{
if (task == nullptr) {
return QString("");
}
return QString::fromUtf8(task->res);
}

QJsonDocument R2Task::getResultJson()
{
if (task == nullptr) {
return QJsonDocument();
}
return Core()->parseJson(task->res, task->cmd);
}

const char *R2Task::getResultRaw()
{
return task->res;
return task != nullptr? task->res: nullptr;
}
7 changes: 4 additions & 3 deletions src/core/Iaito.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ RCoreLocked::RCoreLocked(IaitoCore *core)
assert(core->coreLockDepth >= 0);
core->coreLockDepth++;
if (core->coreLockDepth == 1) {
assert(core->coreBed);
r_cons_sleep_end(core->coreBed);
core->coreBed = nullptr;
if (core->coreBed) {
r_cons_sleep_end(core->coreBed);
core->coreBed = nullptr;
}
}
}

Expand Down

0 comments on commit 28a1099

Please sign in to comment.