net: sockets: tls: Fix net_context referencing

TLS sockets did not increase refcount of a net_context running TCP,
which could lead to a crash upon TCP disconnection.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2020-02-14 11:36:17 +01:00 committed by Jukka Rissanen
commit 56566ad497

View file

@ -1174,6 +1174,10 @@ static int ztls_socket(int family, int type, int proto)
ctx->tls->tls_version = tls_proto;
}
if (proto == IPPROTO_TCP) {
net_context_ref(ctx);
}
z_finalize_fd(
fd, ctx, (const struct fd_op_vtable *)&tls_sock_fd_op_vtable);
@ -1298,6 +1302,7 @@ int ztls_accept_ctx(struct net_context *parent, struct sockaddr *addr,
}
net_context_set_accepting(child, false);
net_context_ref(child);
z_finalize_fd(
fd, child, (const struct fd_op_vtable *)&tls_sock_fd_op_vtable);