src: Fix memory leaks in generate_test_instance() by returning values instead of pointers
Problem:
The current `generate_test_instance()` function returns `std::list<T*>`,
which creates memory management issues:
- Inconsistent lifecycle management of test instances
- Callers don't always properly clean up allocated memory
- Results in ASan memory leak reports in unit tests and ceph-dencoder
Solution:
Change `generate_test_instance()` to return `std::list<T>` instead of `std::list<T*>`:
Core Changes:
- Modified all classes with `generate_test_instance()` to return `std::list<T>`
- Use `emplace_back()` without parameters** to avoid copy/move
constructors for classes that don't define them
- Updated ceph-dencoder to handle the new return type
ceph-dencoder Adaptations:
Since `m_list` now holds `T` objects instead of `T*`, and we can't
assume `T` is copyable/moveable:
- Keep `m_object` as a pointer for flexibility
- Handle two scenarios:
1. `m_object` points to an element in `m_list`
2. `m_object` points to a decoded instance (requires manual cleanup)
- Introduce `make_ptr()` as a factory function to create a smart pointer
to conditionally free the managed pointer.
Additional Cleanup:
- Simplify DencoderBase constructor from template to plain
function (extra parameters were never used in derived classes)
With this change, object lifecycles are now managed by value semantics
instead of raw pointers, eliminating memory leaks.
Signed-off-by: Kefu Chai <tchaikov@gmail.com>