Skip to content

Commit

Permalink
fixes #1713 SP pipe_send leaks message if aio is canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Nov 26, 2023
1 parent 003f055 commit 759a2e9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/sp/transport/inproc/inproc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
Expand Down Expand Up @@ -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);

Check warning on line 213 in src/sp/transport/inproc/inproc.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/inproc/inproc.c#L212-L213

Added lines #L212 - L213 were not covered by tests
return;
}

Expand Down
4 changes: 4 additions & 0 deletions src/sp/transport/ipc/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 524 in src/sp/transport/ipc/ipc.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/ipc/ipc.c#L523-L524

Added lines #L523 - L524 were not covered by tests
return;
}
nni_mtx_lock(&p->mtx);
Expand Down
6 changes: 5 additions & 1 deletion src/sp/transport/tcp/tcp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
Expand Down Expand Up @@ -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);

Check warning on line 518 in src/sp/transport/tcp/tcp.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/tcp/tcp.c#L517-L518

Added lines #L517 - L518 were not covered by tests
return;
}
nni_mtx_lock(&p->mtx);
Expand Down
6 changes: 5 additions & 1 deletion src/sp/transport/tls/tls.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
Expand Down Expand Up @@ -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);

Check warning on line 504 in src/sp/transport/tls/tls.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/tls/tls.c#L503-L504

Added lines #L503 - L504 were not covered by tests
return;
}
nni_mtx_lock(&p->mtx);
Expand Down
6 changes: 5 additions & 1 deletion src/sp/transport/ws/websocket.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
Expand Down Expand Up @@ -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);

Check warning on line 164 in src/sp/transport/ws/websocket.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/ws/websocket.c#L163-L164

Added lines #L163 - L164 were not covered by tests
return;
}
nni_mtx_lock(&p->mtx);
Expand Down
6 changes: 5 additions & 1 deletion src/sp/transport/zerotier/zerotier.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2021 Capitar IT Group BV <info@capitar.com>
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 759a2e9

Please sign in to comment.