code: drawterm

Download patch

ref: c6f547e1a46ebbf7a290427fe3a0b66932d671a0
parent: f1a4a54634ef0bd4fcb8402b518bf0061993564e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Oct 2 13:46:30 EDT 2021

devtls: fix bwrite memory leak when channel stops being open (from 9front)

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/kern/devtls.c
+++ b/kern/devtls.c
@@ -1256,6 +1256,9 @@
 if(tr->debug)pdump(BLEN(b), b->rp, "sent:");
 
 
+	if(type == RApplication)
+		checkstate(tr, 0, SOpen);
+
 	ok = SHandshake|SOpen|SRClose;
 	if(type == RAlert)
 		ok |= SAlert;
@@ -1372,7 +1375,6 @@
 		tr->handout += n;
 		break;
 	case Qdata:
-		checkstate(tr, 0, SOpen);
 		tlsrecwrite(tr, RApplication, b);
 		tr->dataout += n;
 		break;