![]() |
TSDuck v3.44-4659
MPEG Transport Stream Toolkit
|
Canary class to detect memory corruption in instable environments. More...
#include <tsCanary.h>
Public Member Functions | |
| Canary ()=default | |
| Constructor with a "good" default value. | |
| ~Canary () | |
| The destructor sets a "bad" canary to detect use-after-free in case of incorrect order of usage. | |
Static Public Member Functions | |
| static const UChar * | Error (const Canary *c) |
| Check that a Canary pointer is valid and get an error message. | |
| static bool | IsValid (const Canary *c) |
| Check that a Canary pointer is valid. | |
| static const UChar * | LogError (const Canary *c) |
| Check that a Canary pointer is valid, get and log an error message on standard error. | |
Canary class to detect memory corruption in instable environments.
Some libraries or operating systems associate a "user-pointer" to an event or some equivalent concept. This user-pointer usually is a user-allocated data structure. It is passed back to the application by the library or operating system at some point in the future.
The application must ensure that the user-allocated structure remains valid as long as the user-pointer is stored in the library or operating system. Otherwise, the application may receive the address of a structure which is no longer valid.
In some cases, it is complicated to understand how long this user pointer is stored. To track potential errors in our interpretation of the various libraries or operating systems logics, we use some internal consistency checks using canaries, values which are altered when the structure is no longer valid.
User-defined data structures which are used as user-pointer for external libraries or operating systems should use a Canary field as first field.
Check that a Canary pointer is valid, get and log an error message on standard error.
| [in] | c | The address of something that is expected to be a valid Canary. |
|
inlinestatic |