Skip to content

Commit 259ed1a

Browse files
committed
Keep the shared memory BIOs alive until both sides are done
1 parent 6338d67 commit 259ed1a

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

dtls/memory-bio-dtls.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ static void* client_thread(void* args)
119119
} while (ret <= 0 &&
120120
((err == WOLFSSL_ERROR_WANT_READ) || (err == WOLFSSL_ERROR_WANT_WRITE)));
121121

122-
/* clean up, wolfSSL_free would also free the WOLFSSL_BIO's so set as NULL
123-
* since they are also being used with srv_ssl and will be free'd there. */
122+
/* drops this thread's BIO references; srv_ssl still holds its own */
124123
wolfSSL_set_bio(cli_ssl, NULL, NULL);
125124
wolfSSL_free(cli_ssl);
126125
wolfSSL_CTX_free(cli_ctx);
@@ -147,6 +146,10 @@ int main()
147146

148147
io.rbio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
149148
io.wbio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
149+
/* cli_ssl and srv_ssl both use these, so take the second reference here or
150+
* whichever side cleans up first frees them under the other. */
151+
wolfSSL_BIO_up_ref(io.rbio);
152+
wolfSSL_BIO_up_ref(io.wbio);
150153
sem_init(&io.bioSem, 0, 1);
151154

152155
/* set up server */

0 commit comments

Comments
 (0)