Fix outbound flow control count

We wrongly added the whole payload length even if we sent part of it.
src: Remove unused function/member
tests: Fix main test fail with address-sanitizer
tests: Fix memory leak
tests: Remove unused variable