libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit e5e5034111debe060863901dbfe3728cc30d6441
parent 31d84d44a39ef70cfa31982d0b3a96052d28c272
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  4 Jun 2015 11:37:05 +0000

I was checking a test app in valgrind and much to my surprise it was complaining about a memleak in libmicrohttpd.
In check_argument_match() a buffer is allocated using strdup() but freed nowhere.

I wouldn't have noticed this leak if it wasn't for valgrind because if a URI is requested without any arguments (my usual case)
the buffer that gets allocated has 'only' a length of 1 byte, thus memory usage will build up very slowly over time.

The patch attached fixes it.
Btw. the indentation of that file is a mess, tabs and spaces are mixed :-|

Regards,
Andreas




Diffstat:
MChangeLog | 3+++
Msrc/microhttpd/digestauth.c | 13+++++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,6 @@ +Thu Jun 4 13:37:05 CEST 2015 + Fixing memory leak in digest authentication. -AW + Wed Jun 03 21:23:47 CEST 2015 Add deprecation compiler messages for deprecated functions and macros. -EG diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c @@ -508,7 +508,10 @@ check_argument_match (struct MHD_Connection *connection, connection, argp); if (MHD_YES != test_header (connection, argp, NULL)) - return MHD_NO; + { + free(argb); + return MHD_NO; + } num_headers++; break; } @@ -527,10 +530,16 @@ check_argument_match (struct MHD_Connection *connection, connection, equals); if (! test_header (connection, argp, equals)) - return MHD_NO; + { + free(argb); + return MHD_NO; + } + num_headers++; argp = amper; } + + free(argb); /* also check that the number of headers matches */ for (pos = connection->headers_received; NULL != pos; pos = pos->next)