git: 9front

Download patch

ref: 764f78a901cba7e56ccb4c7c8248f60cfcc2748b
parent: 88b8b9bdb46acee827b0c5efac1eb90583c9c26a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Sep 25 16:35:04 EDT 2021

devtls: fix bwrite memory leak when channel stops being open

tlsbwrite() would call checkstate() before calling tlsrecwrite()
to make sure the channel is open. however, because checkstate()
only raises the error, the Block* passed wont be freed and
would result in a memory leak.

move the checkstate() call inside tlsrecwrite() to reuse the
error handling that frees the block on error.

--- a/sys/src/9/port/devtls.c
+++ b/sys/src/9/port/devtls.c
@@ -1258,6 +1258,8 @@
 if(tr->debug)pprint("send %zd\n", BLEN(b));
 if(tr->debug)pdump(BLEN(b), b->rp, "sent:");
 
+	if(type == RApplication)
+		checkstate(tr, 0, SOpen);
 
 	ok = SHandshake|SOpen|SRClose;
 	if(type == RAlert)
@@ -1375,7 +1377,6 @@
 		tr->handout += n;
 		break;
 	case Qdata:
-		checkstate(tr, 0, SOpen);
 		tlsrecwrite(tr, RApplication, b);
 		tr->dataout += n;
 		break;
--