envoyproxy / envoyproxy/envoy

Ability to assert on stat lifetime issues in debug build

Open
#18,047 10 comments 0 reactions 0 assignees View on GitHub
area/stats enhancement help wanted
Dominant language
C++
Stars
28.9k
Forks
5.6k
Avg merge
1d 22h
Merged PRs (30d)
430

Description

There have been some issues recently with stat references (`Counter&` et al) outliving their owning `Scope`. This can lead to use-after-free.

One way to help detect this would be for `Counter&` and friends to be replaced with a class `CounterRef`. This class, in a release build, would only contain a `Counter&`, to avoid a huge increase in memory use. But in debug builds. This object would implement the `Counter` interface, passing all calls through to the stored `Counter&`.

In a debug build, this object would also hold a reference to the `Scope` that created it, and call a new method on the `Scope` to inform that it is using a stat from that `Scope`. In `Scope`'s destructor, it would ASSERT if it is still in use by anything.

Hopefully, the macros that create most stats could be modified to work for this, instead of needing to touch all code creates stats.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.