Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,8 @@ static Htop_Reaction actionStrace(State* st) {
assert(Object_isA((const Object*) p, (const ObjectClass*) &Process_class));

TraceScreen* ts = TraceScreen_new(p);
bool ok = TraceScreen_forkTracer(ts);
if (ok) {
InfoScreen_run((InfoScreen*)ts);
}
TraceScreen_forkTracer(ts);
InfoScreen_run((InfoScreen*)ts);
TraceScreen_delete((Object*)ts);
clear();
CRT_enableDelay();
Expand Down
16 changes: 15 additions & 1 deletion TraceScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ void TraceScreen_delete(Object* cast) {
free(InfoScreen_done((InfoScreen*)this));
}

static void TraceScreen_scan(InfoScreen* super) {
TraceScreen* this = (TraceScreen*) super;
if (!this->strace_alive) {
char* err = NULL;
xAsprintf(&err, "%s", strerror(errno));
InfoScreen_addLine(super, err);
free(err);
Comment on lines +66 to +69

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a fixed size buffer and avoid an allocation here. The reason: Avoid a crash in an out of memory situation.

Suggested change
char* err = NULL;
xAsprintf(&err, "%s", strerror(errno));
InfoScreen_addLine(super, err);
free(err);
char err[64];
snprintf(err, sizeof(err), "%s", strerror(errno));
InfoScreen_addLine(super, err);

}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

static void TraceScreen_draw(InfoScreen* this) {
InfoScreen_drawTitled(this, "Trace of process %d - %s", Process_getPid(this->process), Process_getCommand(this->process));
}
Expand Down Expand Up @@ -125,11 +135,14 @@ bool TraceScreen_forkTracer(TraceScreen* this) {

return true;

err:
err: {
int saved_errno = errno;
close(fdpair[1]);
close(fdpair[0]);
errno = saved_errno;
return false;
}
}

static void TraceScreen_updateTrace(InfoScreen* super) {
TraceScreen* this = (TraceScreen*) super;
Expand Down Expand Up @@ -209,6 +222,7 @@ const InfoScreenClass TraceScreen_class = {
.extends = Class(Object),
.delete = TraceScreen_delete
},
.scan = TraceScreen_scan,
.draw = TraceScreen_draw,
.onErr = TraceScreen_updateTrace,
.onKey = TraceScreen_onKey,
Expand Down