Silence Valgrind complaint with EXEC_BACKEND
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 1 Dec 2023 20:30:08 +0000 (22:30 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 1 Dec 2023 20:30:08 +0000 (22:30 +0200)
The padding bytes written to the backend params file were
uninitialized. That's harmless because we don't access the padding
bytes when we read the file back in, but Valgrind doesn't know
that. In any case, clear the padding bytes to make Valgrind happy.

Reported-by: Alexander Lakhin
Discussion: https://www.postgresql.org/message-id/014768ed-8b39-c44f-b07c-098c87b1644c@gmail.com

src/backend/postmaster/postmaster.c

index 7a5cd06c5c9b4ef885ce99d99bc3b8df9d122639..ccc12f91a1675d0c0923515caa22bea1dbac0da2 100644 (file)
@@ -4490,6 +4490,14 @@ internal_forkexec(int argc, char *argv[], Port *port)
    BackendParameters param;
    FILE       *fp;
 
+   /*
+    * Make sure padding bytes are initialized, to prevent Valgrind from
+    * complaining about writing uninitialized bytes to the file.  This isn't
+    * performance critical, and the win32 implementation initializes the
+    * padding bytes to zeros, so do it even when not using Valgrind.
+    */
+   memset(&param, 0, sizeof(BackendParameters));
+
    if (!save_backend_variables(&param, port))
        return -1;              /* log made by save_backend_variables */