It makes no semantical sense to move a reference from a variable
to another without first putting the destination, if it has one.
Otherwise this would be a lost reference, unless it was moved
elsewhere or put manually using bt_put() previously, which is why
BT_MOVE() should always be used for move semantics and BT_PUT() is
preferred to bt_put() to avoid this situation.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
* then sets _src to NULL, effectively moving the ownership of an
* object from one variable to the other.
*
+ * Before assigning _src to _dst, it puts _dst. Therefore it is not safe to
+ * call this function with an uninitialized value of _dst.
+ *
* @param obj Babeltrace object.
*/
#define BT_MOVE(_dst, _src) \
do { \
+ bt_put(_dst); \
(_dst) = (_src);\
(_src) = NULL; \
} while (0)
{
struct bt_value *obj = bt_value_bool_create();
struct bt_value *src;
- struct bt_value *dst;
+ struct bt_value *dst = NULL;
assert(obj);
BT_PUT(obj);