Fix issues with buffer leak on HTTP upgrade