about summary refs log tree commit homepage
path: root/ext/unicorn_http/unicorn_http.rl
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-02-12 23:59:55 -0800
committerEric Wong <normalperson@yhbt.net>2010-02-13 00:34:50 -0800
commitafdc6fce5f7e34a5c07f24204625cd466e93e5ac (patch)
tree1dfb1c5d5e0dccae3480609147b6e7dfb1226b48 /ext/unicorn_http/unicorn_http.rl
parent615cede23579906b486c7a18bdeb22d04864a6ea (diff)
downloadunicorn-afdc6fce5f7e34a5c07f24204625cd466e93e5ac.tar.gz
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.
Diffstat (limited to 'ext/unicorn_http/unicorn_http.rl')
-rw-r--r--ext/unicorn_http/unicorn_http.rl2
1 files changed, 1 insertions, 1 deletions
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl
index 6232e2c..a95224c 100644
--- a/ext/unicorn_http/unicorn_http.rl
+++ b/ext/unicorn_http/unicorn_http.rl
@@ -439,7 +439,7 @@ static void hp_mark(void *ptr)
 static VALUE HttpParser_alloc(VALUE klass)
 {
   struct http_parser *hp;
-  return Data_Make_Struct(klass, struct http_parser, hp_mark, NULL, hp);
+  return Data_Make_Struct(klass, struct http_parser, hp_mark, -1, hp);
 }