diff --git a/apps/app_dial.c b/apps/app_dial.c
index a42edf7a06113c5267c8611f28bd56e1bb07d7af..ecf09e868898d728cdbd32fee7dd64dd0b139db7 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -1462,6 +1462,27 @@ static void set_dial_features(struct ast_flags64 *opts, struct ast_dial_features
 	ast_app_options2str64(dial_exec_options, &perm_opts, features->options, sizeof(features->options));
 }
 
+static void end_bridge_callback(void *data)
+{
+	char buf[80];
+	time_t end;
+	struct ast_channel *chan = data;
+
+	time(&end);
+
+	ast_channel_lock(chan);
+	if (chan->cdr->answer.tv_sec) {
+		snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->answer.tv_sec);
+		pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
+	}
+
+	if (chan->cdr->start.tv_sec) {
+		snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->start.tv_sec);
+		pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
+	}
+	ast_channel_unlock(chan);
+}
+
 static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags64 *peerflags, int *continue_exec)
 {
 	int res = -1; /* default: error */
@@ -2117,27 +2138,6 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
 		if (res) { /* some error */
 			res = -1;
 		} else {
-			auto void end_bridge_callback(void);
-			void end_bridge_callback (void)
-			{
-				char buf[80];
-				time_t end;
-
-				time(&end);
-
-				ast_channel_lock(chan);
-				if (chan->cdr->answer.tv_sec) {
-					snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->answer.tv_sec);
-					pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
-				}
-
-				if (chan->cdr->start.tv_sec) {
-					snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->start.tv_sec);
-					pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
-				}
-				ast_channel_unlock(chan);
-			}
-
 			if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
 				ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
 			if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
@@ -2162,6 +2162,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
 				ast_set_flag(&(config.features_caller), AST_FEATURE_NO_H_EXTEN);
 
 			config.end_bridge_callback = end_bridge_callback;
+			config.end_bridge_callback_data = chan;
 
 			if (moh) {
 				moh = 0;
diff --git a/apps/app_followme.c b/apps/app_followme.c
index 6e29ec114777f18dc494756128879f32c9245c59..1d324bdc27f06c73e1ce045ed8e651a07a5aa4d6 100644
--- a/apps/app_followme.c
+++ b/apps/app_followme.c
@@ -971,6 +971,27 @@ static struct call_followme *find_realtime(const char *name)
 	return new;
 }
 
+static void end_bridge_callback(void *data)
+{
+	char buf[80];
+	time_t end;
+	struct ast_channel *chan = data;
+
+	time(&end);
+
+	ast_channel_lock(chan);
+	if (chan->cdr->answer.tv_sec) {
+		snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->answer.tv_sec);
+		pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
+	}
+
+	if (chan->cdr->start.tv_sec) {
+		snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->start.tv_sec);
+		pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
+	}
+	ast_channel_unlock(chan);
+}
+
 static int app_exec(struct ast_channel *chan, void *data)
 {
 	struct fm_args targs;
@@ -1085,27 +1106,6 @@ static int app_exec(struct ast_channel *chan, void *data)
 			ast_stream_and_wait(chan, targs.sorryprompt, "");
 		res = 0;
 	} else {
-		auto void end_bridge_callback(void);
-		void end_bridge_callback (void)
-		{
-			char buf[80];
-			time_t end;
-
-			time(&end);
-
-			ast_channel_lock(chan);
-			if (chan->cdr->answer.tv_sec) {
-				snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->answer.tv_sec);
-				pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
-			}
-
-			if (chan->cdr->start.tv_sec) {
-				snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->start.tv_sec);
-				pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
-			}
-			ast_channel_unlock(chan);
-		}
-
 		caller = chan;
 		outbound = targs.outbound;
 		/* Bridge the two channels. */
@@ -1115,6 +1115,7 @@ static int app_exec(struct ast_channel *chan, void *data)
 		ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
 		ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
 		config.end_bridge_callback = end_bridge_callback;
+		config.end_bridge_callback_data = chan;
 
 		ast_moh_stop(caller);
 		/* Be sure no generators are left on it */
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 41ed743e334c9d39f003f59391f9cfbd42faa6cb..b3081028d9cb1d68bd8c876726d1a8adb04a5119 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -3354,6 +3354,15 @@ static void setup_transfer_datastore(struct queue_ent *qe, struct member *member
 	ast_channel_unlock(qe->chan);
 }
 
+static void end_bridge_callback(void *data)
+{
+	struct queue_ent *qe = data;
+
+	ao2_lock(qe->parent);
+	set_queue_variables(qe);
+	ao2_unlock(qe->parent);
+}
+
 /*! \brief A large function which calls members, updates statistics, and bridges the caller and a member
  * 
  * Here is the process of this function
@@ -3421,13 +3430,6 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
 	int callcompletedinsl;
 	struct ao2_iterator memi;
 	struct ast_datastore *datastore;
-	auto void end_bridge_callback(void);
-	void end_bridge_callback(void)
-	{
-		ao2_lock(qe->parent);
-		set_queue_variables(qe);
-		ao2_unlock(qe->parent);
-	}
 
 	ast_channel_lock(qe->chan);
 	datastore = ast_channel_datastore_find(qe->chan, &dialed_interface_info, NULL);
@@ -3499,6 +3501,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
 		}
 
 	bridge_config.end_bridge_callback = end_bridge_callback;
+	bridge_config.end_bridge_callback_data = qe;
 
 	/* Hold the lock while we setup the outgoing calls */
 	if (use_weight)
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 2f212cf653c6d2df52f88b97495427342bf518e4..c1423462eba93effe12899a9bdb6f766f1df8323 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -584,7 +584,8 @@ struct ast_bridge_config {
 	const char *start_sound;
 	int firstpass;
 	unsigned int flags;
-	void (* end_bridge_callback)(void);   /*!< A callback that is called after a bridge attempt */
+	void (* end_bridge_callback)(void *);   /*!< A callback that is called after a bridge attempt */
+	void *end_bridge_callback_data;         /*!< Data passed to the callback */
 };
 
 struct chanmon;
diff --git a/main/features.c b/main/features.c
index 276328365078cc07f91efb39295b32f40875eee9..ed13ee4fc74fc50a38dcce52568d860b15688e85 100644
--- a/main/features.c
+++ b/main/features.c
@@ -2448,7 +2448,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
 	}
    before_you_go:
 	if (res != AST_PBX_KEEPALIVE && config->end_bridge_callback) {
-		config->end_bridge_callback();
+		config->end_bridge_callback(config->end_bridge_callback_data);
 	}
 
 	/* run the hangup exten on the chan object IFF it was NOT involved in a parking situation