diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 79e570b391429b84cce1fcc0d0e1e065b25894f5..5a271eea4207501211f2b94a68607745f799b385 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -2607,14 +2607,15 @@ static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_sessi
 				ao2_lock(me);
 				if (!(packet = AST_LIST_REMOVE_HEAD(&me->packet_q, entry))) {
 					ast_log(LOG_WARNING, "TCPTLS thread alert_pipe indicated packet should be sent, but frame_q is empty");
-				} else if (ast_tcptls_server_write(tcptls_session, ast_str_buffer(packet->data), packet->len) == -1) {
-					ast_log(LOG_WARNING, "Failure to write to tcp/tls socket\n");
 				}
+				ao2_unlock(me);
 
 				if (packet) {
+					if (ast_tcptls_server_write(tcptls_session, ast_str_buffer(packet->data), packet->len) == -1) {
+						ast_log(LOG_WARNING, "Failure to write to tcp/tls socket\n");
+					}
 					ao2_t_ref(packet, -1, "tcptls packet sent, this is no longer needed");
 				}
-				ao2_unlock(me);
 				break;
 			default:
 				ast_log(LOG_ERROR, "Unknown tcptls thread alert '%d'\n", alert);