Fix memory leaks found under AddressSanitizer

- readconfig() kept its line buffer and argument array on every error
  return, so each refused reload leaked them.
- A filter refusing a connection in filter_client (TLS: a failed
  handshake) was not kept, so its filter_clear never ran and the state
  it made was lost. makefilters() now clears it, and empties the slot
  first: a pooled worker's slot may hold the previous connection's.
- ssl_filter_close() freed the client CA paths but not the server ones,
  for every TLS service set up.
- Compiled patterns were never freed: an ACL's (pcre: and regex: host
  names), an httpsrv rule's. copyacl() shared them between the
  configuration's ACL and each service's copy; each copy now compiles
  its own, and freeacl() and freehttprules() free them.

What LeakSanitizer still reports is OpenSSL's per-thread random
generator state of pooled threads, released only by OpenSSL at exit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir DubrovinandClaude Opus 5.5 committed 2026-10-14 20:15:01 +03:00
1 parent 1a193eb82d
commit 796e9f8156
4 files changed
+46 -6

No files matched your search

+12 -5
View File
@@ -2334,6 +2334,7 @@ int readconfig(FILE * fp){
if( !(buf = malloc(bufsize)) || ! (argv = malloc((NPARAMS + 1) * sizeof(unsigned char *))) ) {
fprintf(stderr, "No memory for configuration");
if(buf) free(buf);
return(10);
}
for (linenum = 1; fgets((char *)buf, STRINGBUF, fp); linenum++){
@@ -2343,7 +2344,8 @@ int readconfig(FILE * fp){
argc = parsestr (buf, argv, NPARAMS-1, &buf, &inbuf, &bufsize);
if(argc < 1) {
fprintf(stderr, "Parse error line %d\n", linenum);
return(11);
res = 11;
goto DONE;
}
argv[argc] = NULL;
if(!strcmp((char *)argv[0], "end") && argc == 1) {
@@ -2355,23 +2357,28 @@ int readconfig(FILE * fp){
if(!strcmp((char *)argv[0], (char *)cm->command)){
if(argc < cm->minargs || (cm->maxargs && argc > cm->maxargs)){
fprintf(stderr, "Command: '%s' wrong number of arguments , line %d\n", argv[0], linenum);
return(linenum);
res = linenum;
goto DONE;
}
res = (*cm->handler)(argc, argv);
if(res > 0){
fprintf(stderr, "Command: '%s' failed with code %d, line %d\n", argv[0], res, linenum);
return(linenum);
res = linenum;
goto DONE;
}
if(!res) break;
}
}
if(res != 1)continue;
fprintf(stderr, "Unknown command: '%s' line %d\n", argv[0], linenum);
return(linenum);
res = linenum;
goto DONE;
}
res = 0;
DONE:
free(buf);
free(argv);
return 0;
return res;
}