I made a gist with all the relevant information that I can think of:
https://gist.github.com/YassaaaTU/8acf26763d4485943175d76408ab46af
The gist includes the relevant classes and header files as well as the test file.
And the output of the test with and without valgrind
I did not try different approaches because I don’t know what other approaches there are.