Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Bluetooth: shell: Fix connection reference leak #66484

Merged
merged 2 commits into from
Dec 15, 2023

Conversation

MariuszSkamra
Copy link
Collaborator

@MariuszSkamra MariuszSkamra commented Dec 13, 2023

This fixes regression introduced in recently.
Redundant connection reference is taken twice in connected()
callback. The redunant reference was then not returned, and
as a result we had a leak.

This fixes regression introduced in recently.
Redundant connection reference is taken twice in connected()
callback. The redunant reference was then not returned, and
as a result we had a leak.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This basically reverts changes made by
9c8ec58.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
Comment on lines +2846 to +2847
err = bt_conn_le_create(&addr, create_params, BT_LE_CONN_PARAM_DEFAULT,
&conn);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it'd make sense to update bt_conn_le_create() to accept NULL as the last parameter in cases like this (i.e. where you don't do anything meaningful with the pointer even after a successful return).

@@ -694,8 +694,6 @@ static void connected(struct bt_conn *conn, uint8_t err)
}
}

default_conn = bt_conn_ref(conn);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see the bug with the ref getting taken twice for ROLE_PERIPHERAL, but where is default_conn getting set for ROLE_CENTRAL?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see the bug with the ref getting taken twice for ROLE_PERIPHERAL, but where is default_conn getting set for ROLE_CENTRAL?

Nevermind, I'm just blind.

Copy link
Contributor

@msmttchr msmttchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MariuszSkamra, this seems to fix the double reference problem. Thanks

Copy link
Contributor

@HoZHel HoZHel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it fixes re-advertising after a disconnection.

@fabiobaltieri fabiobaltieri merged commit 6e6311e into zephyrproject-rtos:main Dec 15, 2023
19 checks passed
@MariuszSkamra MariuszSkamra deleted the bt_shell_fix branch December 15, 2023 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants