ellzey/libevhtp — pull request #40 by Tibo-lg (2012-04-13 08:07:53+00:00)
Title: Add cleanup functions

I needed to be able to clean the memory used by evhtp when stopping the server, in order to be able to restart it on fatal errors, and to ease the debugging of my code.

It also fixes the compilation with the EVHTP_DISABLE_SSL_FLAG.

I made some test based on the test.c file. Here are the valgrind results :

WITHOUT THREADING AND SSL

==7057== Memcheck, a memory error detector
==7057== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==7057== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==7057== Command: ./test
==7057== Parent PID: 4844
==7057==
==7057==
==7057== HEAP SUMMARY:
==7057== in use at exit: 448 bytes in 8 blocks
==7057== total heap usage: 98 allocs, 90 frees, 14,909 bytes allocated
==7057==
==7057== LEAK SUMMARY:
==7057== definitely lost: 0 bytes in 0 blocks
==7057== indirectly lost: 0 bytes in 0 blocks
==7057== possibly lost: 0 bytes in 0 blocks
==7057== still reachable: 448 bytes in 8 blocks
==7057== suppressed: 0 bytes in 0 blocks
==7057== Reachable blocks (those to which a pointer was found) are not shown.
==7057== To see them, rerun with: --leak-check=full --show-reachable=yes
==7057==
==7057== For counts of detected and suppressed errors, rerun with: -v
==7057== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

WITH THREADING :

==7142== Memcheck, a memory error detector
==7142== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==7142== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==7142== Command: ./test -t
==7142== Parent PID: 4844
==7142==
==7142==
==7142== HEAP SUMMARY:
==7142== in use at exit: 448 bytes in 8 blocks
==7142== total heap usage: 2,266 allocs, 2,258 frees, 392,483 bytes allocated
==7142==
==7142== LEAK SUMMARY:
==7142== definitely lost: 0 bytes in 0 blocks
==7142== indirectly lost: 0 bytes in 0 blocks
==7142== possibly lost: 0 bytes in 0 blocks
==7142== still reachable: 448 bytes in 8 blocks
==7142== suppressed: 0 bytes in 0 blocks
==7142== Reachable blocks (those to which a pointer was found) are not shown.
==7142== To see them, rerun with: --leak-check=full --show-reachable=yes
==7142==
==7142== For counts of detected and suppressed errors, rerun with: -v
==7142== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

WITH SSL (note that I could not succeed to connect to the server in SSL, I get a handshake error) :

Here there is a definitely lost in the SSL library, I don't know how to clean that better, tried a lot of stuff, but nothing worked.

==7233== Memcheck, a memory error detector
==7233== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==7233== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==7233== Command: ./test -s HPD_cert.pem
==7233== Parent PID: 4844
==7233==
==7233==
==7233== HEAP SUMMARY:
==7233== in use at exit: 536 bytes in 11 blocks
==7233== total heap usage: 2,794 allocs, 2,783 frees, 135,212 bytes allocated
==7233==
==7233== 24 bytes in 1 blocks are definitely lost in loss record 1 of 10
==7233== at 0x4C28F9F: malloc (vg_replace_malloc.c:236)
==7233== by 0x55299C3: CRYPTO_malloc (in /lib/x86_64-linux-gnu/libcrypto.so.1.0.0)
==7233== by 0x52B10DB: ??? (in /lib/x86_64-linux-gnu/libssl.so.1.0.0)
==7233== by 0x52B2F98: SSL_COMP_get_compression_methods (in /lib/x86_64-linux-gnu/libssl.so.1.0.0)
==7233== by 0x52B80E7: SSL_library_init (in /lib/x86_64-linux-gnu/libssl.so.1.0.0)
==7233== by 0x40ED11: evhtp_ssl_init (evhtp.c:2806)
==7233== by 0x40827E: main (test.c:578)
==7233==
==7233== LEAK SUMMARY:
==7233== definitely lost: 24 bytes in 1 blocks
==7233== indirectly lost: 0 bytes in 0 blocks
==7233== possibly lost: 0 bytes in 0 blocks
==7233== still reachable: 512 bytes in 10 blocks
==7233== suppressed: 0 bytes in 0 blocks
==7233== Reachable blocks (those to which a pointer was found) are not shown.
==7233== To see them, rerun with: --leak-check=full --show-reachable=yes
==7233==
==7233== For counts of detected and suppressed errors, rerun with: -v
==7233== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)'

I think it needs more test and some improvements, but it might be useful to others to be able to cleanup at exit.