kellabyte/Haywire — pull request #29 by jbcrail (2013-06-04 01:22:15+00:00)
Title: Fix for keep-alive memory leak

Building upon your work in `http_request_on_header_field()`, I refactored the code that set and deleted a request header into separate functions. I changed the body of `http_request_on_header_field()` and `http_request_on_header_value()` to be the same.

I ran the following tests:

bin/wrk/wrk -d20 -t8 -c64 --pipeline 2048 http://0.0.0.0:8000
ab -n 100000 -c 8 -k http://0.0.0.0:8000/
httperf-0.9.0/src/httperf --server=localhost --port=8000 --num-conns=4 --num-calls=10000

The result from valgrind was much better:

```text
$ valgrind --tool=memcheck --leak-check=full --show-reachable=yes --track-origins=yes ./builds/unix/debug/hello_world
==21344== Memcheck, a memory error detector
==21344== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==21344== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==21344== Command: ./builds/unix/debug/hello_world
==21344==
Added route /
Listening on 0.0.0.0:8000
read: connection reset by peer
^C==21344==
==21344== HEAP SUMMARY:
==21344== in use at exit: 1,408 bytes in 3 blocks
==21344== total heap usage: 1,814,546 allocs, 1,814,543 frees, 9,362,912,032 bytes allocated
==21344==
==21344== 192 bytes in 1 blocks are still reachable in loss record 1 of 3
==21344== at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21344== by 0x404972: rxt_init (radix.c:467)
==21344== by 0x4034F1: hw_http_add_route (http_server.c:41)
==21344== by 0x4034B9: main (program.c:25)
==21344==
==21344== 192 bytes in 1 blocks are still reachable in loss record 2 of 3
==21344== at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21344== by 0x403FDE: rxt_put (radix.c:240)
==21344== by 0x403512: hw_http_add_route (http_server.c:43)
==21344== by 0x4034B9: main (program.c:25)
==21344==
==21344== 1,024 bytes in 1 blocks are still reachable in loss record 3 of 3
==21344== at 0x4C2CF8E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21344== by 0x40AA49: maybe_resize (core.c:605)
==21344== by 0x40AC31: uv__io_start (core.c:642)
==21344== by 0x4126BA: uv__read_start_common (stream.c:1301)
==21344== by 0x412732: uv_read_start (stream.c:1310)
==21344== by 0x4036FE: http_stream_on_connect (http_server.c:89)
==21344== by 0x4106E6: uv__server_io (stream.c:533)
==21344== by 0x4179C2: uv__io_poll (linux-core.c:211)
==21344== by 0x40A53F: uv_run (core.c:317)
==21344== by 0x403643: hw_http_open (http_server.c:71)
==21344== by 0x4034C8: main (program.c:26)
==21344==
==21344== LEAK SUMMARY:
==21344== definitely lost: 0 bytes in 0 blocks
==21344== indirectly lost: 0 bytes in 0 blocks
==21344== possibly lost: 0 bytes in 0 blocks
==21344== still reachable: 1,408 bytes in 3 blocks
==21344== suppressed: 0 bytes in 0 blocks
==21344==
==21344== For counts of detected and suppressed errors, rerun with: -v
==21344== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
```