davidmoreno / onion

C library to create simple HTTP servers and Web Applications.
http://www.coralbits.com/libonion/
Other
2.02k stars 250 forks source link

libonion leaks 31 bytes in all programs #254

Closed ghost closed 4 years ago

ghost commented 5 years ago

I have discovered that all programs written with libonion that receive at least one request leak 31 bytes after being closed.

Steps to reproduce:

davidmoreno commented 5 years ago

It is a required mem leak, to prevent having to calculate the datetime string for every request, and do it only at most once every second. It is a small optimization.

I guess it could be just a global string with fixed length, and avoid the malloc. Ot have the pointer instead of globally in the onion struct.

Actually this code is a bit ugly (response.c lines 95 to 138) so feel free to submit a pull request with it in an function just for this (time string keeping), and to fix the mem leak... although the only option I see is to pre reserve it at the onion object, or maybe with a static char datetime[32]. Maybe even we can avoid the rw lock and do an atomic pointer swap.

ghost commented 5 years ago

Aha, didn't know it was by design. Thanks for the explanation! Maybe it would be good to add this info into README as I spent some time trying to find where my program is leaking.. only to find it wasn't my code that leaked.