http: fix parser double-free in _http_client.js
authorFedor Indutny <fedor.indutny@gmail.com>
Wed, 27 Nov 2013 10:54:58 +0000 (14:54 +0400)
committerTimothy J Fontaine <tjfontaine@gmail.com>
Wed, 27 Nov 2013 23:37:56 +0000 (15:37 -0800)
commit5ce4eed54dceb15c34d3508e733124edd282601b
tree824e96f5efba5c2a807d904cadb0f2da10da3e3e
parentc749a841cd828cc85a0fa2052e664ce5e0b6273b
http: fix parser double-free in _http_client.js

HTTP Parser instance was freed twice, leading to the reusal of it
in several different requests simultaneously.

The flow:

`socketCloseListener` is firing, which calls `socket.read()` to flush
any queued data, `socket.buffer` has data which emits and fires
`socketOnData` in sync, this triggers a parser error which frees the
parser, `socketCloseListener` resumes execution only to have the wrong
parser associated with the socket.

The fix is to only cache the parser after the flushing from the socket,
and to assert in `socketOnData` that `socket === parser.socket`

fix #6451
lib/_http_client.js
test/simple/test-http-client-parser-double-free.js [new file with mode: 0644]