From 759a2e9d65bd093ac9740d2cf0aa38a0212c5c23 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 26 Nov 2023 09:53:40 -0800 Subject: [PATCH] fixes #1713 SP pipe_send leaks message if aio is canceled --- src/sp/transport/inproc/inproc.c | 6 +++++- src/sp/transport/ipc/ipc.c | 4 ++++ src/sp/transport/tcp/tcp.c | 6 +++++- src/sp/transport/tls/tls.c | 6 +++++- src/sp/transport/ws/websocket.c | 6 +++++- src/sp/transport/zerotier/zerotier.c | 6 +++++- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/sp/transport/inproc/inproc.c b/src/sp/transport/inproc/inproc.c index 2ab8b0b99..978b66797 100644 --- a/src/sp/transport/inproc/inproc.c +++ b/src/sp/transport/inproc/inproc.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2023 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -207,6 +207,10 @@ inproc_pipe_send(void *arg, nni_aio *aio) int rv; if (nni_aio_begin(aio) != 0) { + // No way to give the message back to the protocol, so + // we just discard it silently to prevent it from leaking. + nni_msg_free(nni_aio_get_msg(aio)); + nni_aio_set_msg(aio, NULL); return; } diff --git a/src/sp/transport/ipc/ipc.c b/src/sp/transport/ipc/ipc.c index df27ad238..a8fc954b2 100644 --- a/src/sp/transport/ipc/ipc.c +++ b/src/sp/transport/ipc/ipc.c @@ -518,6 +518,10 @@ ipc_pipe_send(void *arg, nni_aio *aio) int rv; if (nni_aio_begin(aio) != 0) { + // No way to give the message back to the protocol, so + // we just discard it silently to prevent it from leaking. + nni_msg_free(nni_aio_get_msg(aio)); + nni_aio_set_msg(aio, NULL); return; } nni_mtx_lock(&p->mtx); diff --git a/src/sp/transport/tcp/tcp.c b/src/sp/transport/tcp/tcp.c index d6050d458..ba6c546ce 100644 --- a/src/sp/transport/tcp/tcp.c +++ b/src/sp/transport/tcp/tcp.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2023 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -512,6 +512,10 @@ tcptran_pipe_send(void *arg, nni_aio *aio) int rv; if (nni_aio_begin(aio) != 0) { + // No way to give the message back to the protocol, so + // we just discard it silently to prevent it from leaking. + nni_msg_free(nni_aio_get_msg(aio)); + nni_aio_set_msg(aio, NULL); return; } nni_mtx_lock(&p->mtx); diff --git a/src/sp/transport/tls/tls.c b/src/sp/transport/tls/tls.c index 4db9170d1..e34a3ab28 100644 --- a/src/sp/transport/tls/tls.c +++ b/src/sp/transport/tls/tls.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2023 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -498,6 +498,10 @@ tlstran_pipe_send(void *arg, nni_aio *aio) int rv; if (nni_aio_begin(aio) != 0) { + // No way to give the message back to the protocol, so + // we just discard it silently to prevent it from leaking. + nni_msg_free(nni_aio_get_msg(aio)); + nni_aio_set_msg(aio, NULL); return; } nni_mtx_lock(&p->mtx); diff --git a/src/sp/transport/ws/websocket.c b/src/sp/transport/ws/websocket.c index 7cf9949f1..a46ea58bc 100644 --- a/src/sp/transport/ws/websocket.c +++ b/src/sp/transport/ws/websocket.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2023 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -158,6 +158,10 @@ wstran_pipe_send(void *arg, nni_aio *aio) int rv; if (nni_aio_begin(aio) != 0) { + // No way to give the message back to the protocol, so + // we just discard it silently to prevent it from leaking. + nni_msg_free(nni_aio_get_msg(aio)); + nni_aio_set_msg(aio, NULL); return; } nni_mtx_lock(&p->mtx); diff --git a/src/sp/transport/zerotier/zerotier.c b/src/sp/transport/zerotier/zerotier.c index 5658fb18e..f3de35047 100644 --- a/src/sp/transport/zerotier/zerotier.c +++ b/src/sp/transport/zerotier/zerotier.c @@ -1,6 +1,6 @@ // +// Copyright 2023 Staysail Systems, Inc. // Copyright 2021 Capitar IT Group BV -// Copyright 2020 Staysail Systems, Inc. // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -1821,6 +1821,10 @@ zt_pipe_send(void *arg, nni_aio *aio) nni_msg *m; if (nni_aio_begin(aio) != 0) { + // No way to give the message back to the protocol, so + // we just discard it silently to prevent it from leaking. + nni_msg_free(nni_aio_get_msg(aio)); + nni_aio_set_msg(aio, NULL); return; } if ((m = nni_aio_get_msg(aio)) == NULL) {