c6f547e1a46ebbf7a290427fe3a0b66932d671a0 — cinap_lenrek 3 months ago f1a4a54
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.
1 files changed, 3 insertions(+), 1 deletions(-)

M kern/devtls.c
M kern/devtls.c => kern/devtls.c +3 -1
@@ 1256,6 1256,9 @@ 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)
		ok |= SAlert;

@@ 1372,7 1375,6 @@ tlsbwrite(Chan *c, Block *b, ulong offset)
		tr->handout += n;
	case Qdata:
		checkstate(tr, 0, SOpen);
		tlsrecwrite(tr, RApplication, b);
		tr->dataout += n;