Project

General

Profile

Actions

Bug #2894

closed

Memory leak if two fcgi calls with one request (authentication and response)

Added by rschmid almost 7 years ago. Updated over 6 years ago.

Status:
Fixed
Priority:
Normal
Category:
mod_fastcgi
Target version:
ASK QUESTIONS IN Forums:

Description

Hello,

if lighttpd (1.4.49) is configured to authenticate via fcgi and also responds via a second fcgi (or the same fcgi), the memory grows slowly.
This is because in gw_backend.c the chunk queue is only reset after authentication and then newly initialized in mod_fastcgi.c. The reseted memory remains.
gw_backend.c (line 1117):

static void handler_ctx_clear(gw_handler_ctx *hctx) {
    /* caller MUST have called gw_backend_close(srv, hctx) if necessary */

    ...

    if (hctx->rb) chunkqueue_reset(hctx->rb);

    ...

}

mod_fastcgi.c (line 511)
static handler_t fcgi_check_extension(server *srv, connection *con, void *p_d, int uri_path_handler) {

    if (con->mode == p->id) {
        ...
        hctx->rb = chunkqueue_init();
    }

    return HANDLER_GO_ON;
}

A possible patch that worked for me is to look if the chunk queue already exists:

--- a/src/mod_fastcgi.c    2018-06-22 07:31:34.273162458 +0200
+++ b/src/mod_fastcgi.c    2018-06-22 08:10:17.881130326 +0200
@@ -508,7 +508,10 @@ static handler_t fcgi_check_extension(se
         hctx->opts.pdata = hctx;
         hctx->stdin_append = fcgi_stdin_append;
         hctx->create_env = fcgi_create_env;
-        hctx->rb = chunkqueue_init();
+        if(!hctx->rb)
+        {
+            hctx->rb = chunkqueue_init();
+        }
     }

     return HANDLER_GO_ON;

Added by gstrauss over 6 years ago

Revision eb429c9c (diff)

[mod_fastcgi] fix memleak with FastCGI auth,resp (fixes #2894)

fix memleak in mod_fastcgi when FastCGI is used for both authentication
and response on the same request

(thx rschmid)

x-ref:
"Memory leak if two fcgi calls with one request (authentication and response)"
https://redmine.lighttpd.net/issues/2894

Actions

Also available in: Atom