From b2c1a352bfa105c1d289dae31cb47b8fcc3963ff Mon Sep 17 00:00:00 2001
From: Guus Sliepen <guus@sliepen.org>
Date: Wed, 27 Feb 2019 20:05:00 +0100
Subject: [PATCH] Keep a copy of the old receive callback before calling
 reset_connection().

The latter function clears the receive callback, so make a copy before
calling trying to call the receive callback for the final time.
---
 utcp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/utcp.c b/utcp.c
index d09b9e7..9fb68ae 100644
--- a/utcp.c
+++ b/utcp.c
@@ -1664,11 +1664,13 @@ void utcp_abort_all_connections(struct utcp *utcp) {
 			continue;
 		}
 
+		utcp_recv_t old_recv = c->recv;
+
 		reset_connection(c);
 
-		if(c->recv) {
+		if(old_recv) {
 			errno = 0;
-			c->recv(c, NULL, 0);
+			old_recv(c, NULL, 0);
 		}
 	}
 
-- 
2.39.5