diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index c9dac9a..6b72f99 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
static gboolean auto_config(gpointer data)
{
struct a2dp_setup *setup = data;
- struct btd_device *dev = avdtp_get_device(setup->session);
+ struct btd_device *dev = NULL;
struct btd_service *service;
/* Check if configuration was aborted */
if (setup->err != NULL)
goto done;
+ dev = avdtp_get_device(setup->session);
+
avdtp_stream_add_cb(setup->session, setup->stream,
stream_state_changed, setup->sep);