clamd: Fix valgrind test failure (#1570)

ClamD opens at least one socket that is then passed to server-th as
newly allocated memory. server-th then appends to this structure with
additional FDs as it handles connections. While cleaning up during
server shutdown, server-th loops through all FDs and closes them,
followed by clamd closing the FDs it opened, which have now been
previously closed by server-th. 

This fix skips closing the FDs in server-th that were opened in clamd.

CLAM-2850
This commit is contained in:
John Humlick 2025-09-09 10:07:34 -07:00 committed by GitHub
parent d758c00537
commit f039849dc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -499,6 +499,7 @@ struct acceptdata {
struct fd_data fds;
struct fd_data recv_fds;
pthread_cond_t cond_nfds;
unsigned initial_fds;
int max_queue;
int commandtimeout;
int syncpipe_wake_recv[2];
@ -507,7 +508,7 @@ struct acceptdata {
#define ACCEPTDATA_INIT(mutex1, mutex2) \
{ \
FDS_INIT(mutex1), FDS_INIT(mutex2), PTHREAD_COND_INITIALIZER, 0, 0, {-1, -1}, \
FDS_INIT(mutex1), FDS_INIT(mutex2), PTHREAD_COND_INITIALIZER, 0, 0, 0, {-1, -1}, \
{ \
-1, -1 \
} \
@ -646,7 +647,7 @@ static void *acceptloop_th(void *arg)
if (sd_listen_fds(0) == 0) {
/* only close the sockets, when not using systemd socket activation */
for (i = 0; i < fds->nfds; i++) {
for (i = data->initial_fds; i < fds->nfds; i++) {
if (fds->buf[i].fd == -1)
continue;
logg(LOGG_DEBUG_NV, "Shutdown: closed fd %d\n", fds->buf[i].fd);
@ -923,6 +924,9 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
unsigned int selfchk;
threadpool_t *thr_pool;
// Initial sockets will be closed in clamd.c
acceptdata.initial_fds = nsockets;
#ifndef _WIN32
memset(&sigact, 0, sizeof(struct sigaction));
#endif