From d928b4271dda8268292763f33f3c45bbe39878fa Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Fri, 28 Apr 2017 08:00:36 -0600 Subject: [PATCH] net/socket: fix cloning of local and raw sockets --- net/socket/net_clone.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/socket/net_clone.c b/net/socket/net_clone.c index a08c236329..d720eb8731 100644 --- a/net/socket/net_clone.c +++ b/net/socket/net_clone.c @@ -50,6 +50,8 @@ #include "tcp/tcp.h" #include "udp/udp.h" +#include "pkt/pkt.h" +#include "local/local.h" #include "socket/socket.h" #include "usrsock/usrsock.h" @@ -97,6 +99,24 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2) DEBUGASSERT(psock2->s_conn); psock2->s_crefs = 1; /* One reference on the new socket itself */ +#ifdef CONFIG_NET_LOCAL + if (psock2->s_domain == PF_LOCAL) + { + FAR struct local_conn_s *conn = psock2->s_conn; + DEBUGASSERT(conn->lc_crefs > 0 && conn->lc_crefs < 255); + conn->lc_crefs++; + } + else +#endif +#ifdef CONFIG_NET_PKT + if (psock2->s_type == SOCK_RAW) + { + FAR struct pkt_conn_s *conn = psock2->s_conn; + DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255); + conn->crefs++; + } + else +#endif #ifdef NET_TCP_HAVE_STACK if (psock2->s_type == SOCK_STREAM) {