davidmoreno / onion

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

onion_request_get_language_code leaks data each time it's called #255

Closed ghost closed 4 years ago

ghost commented 5 years ago

I have discovered that everytime onion_request_get_language_code is called, it leaks a few bytes of data (length apparently depends on the length of the Accept-Language header).

Steps to reproduce:

The number of bytes and the number of blocks shall multiply by the number of requests you make (given that your Accept-Language header stays the same).

AlysonNumberFIVE commented 4 years ago

I'm not sure if this issue's still open, but after reading the source code it seems like onion_request_get_language_code(req) makes a call to strdup which allocates its bytes. The reason it would be leaking after each run is because inside the print statement, onion_request_get_language_code(req) is malloced but has no chance to ever be freed.

I ran it like this

char *value = onion_request_get_language_code(req);
ONION_INFO("%s", value);
if (value)
    free(value);

and my leak count is 0.

I don't know if this is the issue or perhaps I'm not understanding something?

ghost commented 4 years ago

Hello,

thank you, this seems to be the issue. Also, it turns out that the main issue is my inability to read as this need to free the result is described in the documentation as well.

I'm really sorry for wasting your time.

Best Regards, Ondřej Fiala