1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

hooks: fix segfault during destruction of stats hook

This commit is contained in:
Steffen Vogel 2020-09-13 08:42:30 +02:00
parent a36b93a46d
commit 6ddc34f028

View file

@ -99,8 +99,8 @@ class StatsHook : public Hook {
friend StatsWriteHook;
protected:
StatsReadHook readHook;
StatsWriteHook writeHook;
StatsReadHook *readHook;
StatsWriteHook *writeHook;
enum Stats::Format format;
int verbose;
@ -116,8 +116,6 @@ public:
StatsHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) :
Hook(p, n, fl, prio, en),
readHook(this, p, n, fl, prio, en),
writeHook(this, p, n, fl, prio, en),
format(Stats::Format::HUMAN),
verbose(0),
warmup(500),
@ -125,13 +123,22 @@ public:
output(nullptr),
uri()
{
readHook = new StatsReadHook(this, p, n, fl, prio, en);
writeHook = new StatsWriteHook(this, p, n, fl, prio, en);
if (!readHook || !writeHook)
throw MemoryAllocationError();
/* Add child hooks */
if (node) {
vlist_push(&node->in.hooks, (void *) &readHook);
vlist_push(&node->out.hooks, (void *) &writeHook);
vlist_push(&node->in.hooks, (void *) readHook);
vlist_push(&node->out.hooks, (void *) writeHook);
}
}
StatsHook & operator=(const StatsHook&) = delete;
StatsHook(const StatsHook&) = delete;
virtual void start()
{
assert(state == State::PREPARED);
@ -168,7 +175,7 @@ public:
{
// Only call readHook if it hasnt been added to the node's hook list
if (!node)
return readHook.process(smp);
return readHook->process(smp);
return Hook::Reason::OK;
}