cpp-common/bt2: use `std::unique_ptr` to manage `UserMessageIterator::_mSavedLibError`
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 21 Feb 2024 21:37:27 +0000 (16:37 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
commitea0030320bb23805e0f7a340930e165e84e8eaf0
treea21a02069c2547a441c7c9b015b34a4ddb0bb292
parentbd6e66fd0c3012ad6bcb03cdb3fb687767fb6ccf
cpp-common/bt2: use `std::unique_ptr` to manage `UserMessageIterator::_mSavedLibError`

clang-tidy points out that `UserMessageIterator` has a user-defined
destructor, but default copy constructors and assignment operators.
This is indeed dangerous: if we have an error in `_mSavedLibError` and
the `UserMessageIterator` object gets copied, the error will be released
multiple times, causing a use-after-free.

The most obvious fix would be to explicitly delete the default
definitions of the copy constructors and assignment operators.  But
I think it's a bit more idiomatic C++ to use some RAII type to manage
the error.  In this case `std::unique_ptr` is a good fit.  This lets us
delete the user-defined destructor.  The copy constructors and
assignment operators are implicitly deleted, since `unique_ptr` doesn't
have them.

Change-Id: Ia78bbda6a342192cb35c1b6963d3ad7fccaa7c3f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11844
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common/bt2/component-class-dev.hpp
This page took 0.024917 seconds and 4 git commands to generate.