Today I discovered GNU's #libmicrohttpd. I guess with my mediocre C skills I shouldn't use this for anything facing the web. However, using it for a internal test script that only tells me whether I connected via IPv6 or IPv4 is fun.
I found where the memory leak in GnuTLS happened! I traced it for quite long time to trace it down in multithreaded calls of multiple libraries. it took some time and getting into the libraries internals.
so, the leak happens when gnutls_handshake returns an error. then the internal buffers for handshake headers are not freed properly and leak.
the cheap and dirty solution is to call gnutls_deinit and gnutls_init each time when a session failed a handshake (they may be numerous in long sessions).
this happens only when multiple threads call gnutls_handshake. on a single thread I didn't get any leaks. though, maybe there were no errors because I just had not enough traffic on the socket. though, they claim that gnutls is thread safe. so I'm not sure if everything is all right with such a use. I debug it in libmicrohttpd where I discovered the problem.
the internal fix for GnuTLS doesn't seem that easy. but I will to think on it. maybe the reinitialization from the outside is not that bad.
I will try to make a test example for showing the problem and send bug reports and possible patches to upstream.
#programming #gnutls #libmicrohttpd #memory leaks #bugs #hint #bugfix