Hello,
I was learning about how the bt_conn references work, how to obtain them and free them, and where they are generated.
I was looking at the central_gatt_write example and how it handles it refs and unrefs.
In it i noticed that all bt_conn refs are unref except for the "conn_connected" variable. It is first associated a reference in the gatt_write_common.c, "connected()" callback with "conn_connected = bt_conn_ref(conn);", but the bt_conn_unref() is never used on it, the only thing done is the conn_connected being pointed to NULL in the gatt_write_common.c, "disconnected()" callback with "conn_connected = NULL;".
Shouldn't the conn_connected variable be unref with "bt_conn_unref(conn_connected)" before being given the NULL?
Wouldn't not making the bt_conn_unref() keep an increment every time something connects?
Am I missing something?
Thank you
PS: I also noticed that in the disconnected() function the bt_conn "conn" variable given by said callback is unref in "bt_conn_unref(conn);" is this necessary? Isn't this conn ref unrefed in the bluetooth\host\conn.c, deferred_work() function after calling all the disconnect callbacks?