[PATCH] net/memif: unregister callback on error in listener handler

Dmitriy Matveichev <[email protected]>
Newsgroups org.dpdk.dev
Message-ID <[email protected]>
Fix the crash if a memif client disconnects before a server says hello

Signed-off-by: Dmitriy Matveichev <[email protected]>
---

If a memif client disconnects before a server says hello in memif_listener_handler we get errors 
"MEMIF: memif_msg_send_from_queue(): sendmsg fail: Broken pipe.
EAL: PANIC in eal_intr_thread_main():
Error adding fd 59 epoll_ctl, Bad file descriptor".
During the error handling in this func a socket is freed but the eal_intr_thread_main knows nothing about it. The descriptor becomes invalid after close. 
We should unregister callback from the eal_intr_thread_main loop and only after that we can safely free the socket. 

 .mailmap                         |  1 +
 drivers/net/memif/memif_socket.c | 10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/.mailmap b/.mailmap
index fcb3d1bb3f..d0148b0d9c 100644
--- a/.mailmap
+++ b/.mailmap
@@ -409,6 +409,7 @@ Ding Zhi <[email protected]>
 Diogo Behrens <[email protected]>
 Dirk-Holger Lenz <[email protected]>
 Dmitri Epshtein <[email protected]>
+Dmitriy Matveichev <[email protected]>
 Dmitriy Yakovlev <[email protected]>
 Dmitry Eremin-Solenikov <[email protected]>
 Dmitry Kozlyuk <[email protected]> <[email protected]>
diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c
index 649f8d0e61..898ad75fa6 100644
--- a/drivers/net/memif/memif_socket.c
+++ b/drivers/net/memif/memif_socket.c
@@ -878,14 +878,16 @@ memif_listener_handler(void *arg)
 	return;
 
  error:
-	if (sockfd >= 0) {
-		close(sockfd);
-		sockfd = -1;
-	}
 	if (cc != NULL) {
+		rte_intr_callback_unregister(cc->intr_handle, memif_intr_handler,
+					 cc);
 		rte_intr_instance_free(cc->intr_handle);
 		rte_free(cc);
 	}
+	if (sockfd >= 0) {
+		close(sockfd);
+		sockfd = -1;
+	}
 }
 
 static struct memif_socket *
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.