http: fix memory leak exposed in concurrent servers
commitb30ae5c5f01c36f39b9c301e59d8ad9fb24f7c1b
authorEric Wong <normalperson@yhbt.net>
Sat, 13 Feb 2010 07:59:55 +0000 (12 23:59 -0800)
committerEric Wong <normalperson@yhbt.net>
Sat, 13 Feb 2010 08:31:52 +0000 (13 00:31 -0800)
tree221140413a957ecce9cb34040320c6aa0a8bed6b
parent47c50ed7ebb2a97c2d289eede169f3e2e3f5e89b
http: fix memory leak exposed in concurrent servers

First off, this memory leak DOES NOT affect Unicorn itself.
Unicorn allocates the HttpParser once and always reuses it
in every sequential request.

This leak affects applications which repeatedly allocate a new
HTTP parser.  Thus this bug affects _all_ deployments of
Rainbows! and Zbatery.  These servers allocate a new parser for
every client connection.

I misread the Data_Make_Struct/Data_Wrap_Struct documentation
and ended up passing NULL as the "free" argument instead of -1,
causing the memory to never be freed.

From README.EXT in the MRI source which I misread:
> The free argument is the function to free the pointer
> allocation.  If this is -1, the pointer will be just freed.
> The functions mark and free will be called from garbage
> collector.
ext/unicorn_http/unicorn_http.rl
test/unit/test_http_parser.rb