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.
This commit is contained in:
cinap_lenrek 2021-09-25 20:35:04 +00:00
parent 235ef367d7
commit 1cff923af4

View file

@ -1258,6 +1258,8 @@ tlsrecwrite(TlsRec *tr, int type, Block *b)
if(tr->debug)pprint("send %zd\n", BLEN(b)); if(tr->debug)pprint("send %zd\n", BLEN(b));
if(tr->debug)pdump(BLEN(b), b->rp, "sent:"); if(tr->debug)pdump(BLEN(b), b->rp, "sent:");
if(type == RApplication)
checkstate(tr, 0, SOpen);
ok = SHandshake|SOpen|SRClose; ok = SHandshake|SOpen|SRClose;
if(type == RAlert) if(type == RAlert)
@ -1375,7 +1377,6 @@ tlsbwrite(Chan *c, Block *b, ulong offset)
tr->handout += n; tr->handout += n;
break; break;
case Qdata: case Qdata:
checkstate(tr, 0, SOpen);
tlsrecwrite(tr, RApplication, b); tlsrecwrite(tr, RApplication, b);
tr->dataout += n; tr->dataout += n;
break; break;