Found by Coverity:
CID
1376179 (#1 of 1): Dereference before null check
(REVERSE_INULL)check_after_deref: Null-checking stream_state suggests
that it may be null, but it has already been dereferenced on all paths
leading to the check.
Reorganized this function so we clear the stream_state (set to NULL)
whenever we return success or error, so the caller don't end up using
uninitialized variable.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
int ensure_stream_state_exists(struct bt_notification_iterator *iterator,
struct bt_notification *stream_begin_notif,
struct bt_ctf_stream *notif_stream,
int ensure_stream_state_exists(struct bt_notification_iterator *iterator,
struct bt_notification *stream_begin_notif,
struct bt_ctf_stream *notif_stream,
- struct stream_state **stream_state)
+ struct stream_state **_stream_state)
+ struct stream_state *stream_state = NULL;
- *stream_state = g_hash_table_lookup(iterator->stream_states,
+ stream_state = g_hash_table_lookup(iterator->stream_states,
/*
* This iterator did not bump into this stream yet:
* create a stream state and a "stream begin"
/*
* This iterator did not bump into this stream yet:
* create a stream state and a "stream begin"
- *stream_state = create_stream_state(notif_stream);
+ stream_state = create_stream_state(notif_stream);
if (!stream_state) {
BT_LOGE_STR("Cannot create stream state.");
goto error;
}
if (!stream_state) {
BT_LOGE_STR("Cannot create stream state.");
goto error;
}
- action.payload.add_stream_state.stream_state =
- *stream_state;
+ action.payload.add_stream_state.stream_state = stream_state;
add_action(iterator, &action);
if (stream_begin_notif) {
add_action(iterator, &action);
if (stream_begin_notif) {
- destroy_stream_state(*stream_state);
+ destroy_stream_state(stream_state);
+ stream_state = NULL;
+ *_stream_state = stream_state;