Skip to content

Commit e0f3813

Browse files
rugeGerritsenrlubos
authored andcommitted
Samples: Bluetooth: Fix use of local obtained conn refs
The returned reference is unused. Found using the semantic patch file: ``` @@ local idexpression conn; identifier e; statement S1; @@ * e = bt_conn_le_create(..., &conn); ... when != bt_conn_unref(conn) when != if (e == 0) { <+... bt_conn_unref(conn) ...+> } else S1 ``` Signed-off-by: Rubin Gerritsen <[email protected]>
1 parent c62381d commit e0f3813

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

samples/bluetooth/iso_combined_bis_and_cis/src/combined_bis_cis.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si
105105

106106
if (err) {
107107
LOG_ERR("Create conn to %s failed (%d)", name_str, err);
108+
} else {
109+
bt_conn_unref(conn);
108110
}
109111
}
110112

@@ -226,8 +228,6 @@ static void connected(struct bt_conn *conn, uint8_t err)
226228
if (err) {
227229
LOG_INF("Failed to connect to %s (%u)", addr, err);
228230

229-
bt_conn_unref(conn);
230-
231231
scan_start();
232232
return;
233233
}
@@ -265,8 +265,6 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
265265

266266
LOG_INF("Disconnected: %s (reason 0x%02x)", addr, reason);
267267

268-
bt_conn_unref(conn);
269-
270268
scan_start();
271269
}
272270

samples/bluetooth/iso_time_sync/src/cis_central.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si
8787
&conn);
8888
if (err) {
8989
printk("Create conn to %s failed (%d)\n", name_str, err);
90+
} else {
91+
bt_conn_unref(conn);
9092
}
9193
}
9294

@@ -127,8 +129,6 @@ static void connected(struct bt_conn *conn, uint8_t err)
127129
if (err) {
128130
printk("Failed to connect to %s (%u)\n", addr, err);
129131

130-
bt_conn_unref(conn);
131-
132132
scan_start();
133133
return;
134134
}
@@ -164,8 +164,6 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
164164

165165
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
166166

167-
bt_conn_unref(conn);
168-
169167
scan_start();
170168
}
171169

0 commit comments

Comments
 (0)