From 3daf3e19dad83495e32a6656f851b8caf112ce4f Mon Sep 17 00:00:00 2001 From: dongshengyuan <545258830@qq.com> Date: Thu, 25 Jun 2026 16:40:05 +0800 Subject: [PATCH] core: fix fd leak in exec_shared_runtime_deserialize_one The userns/netns/ipcns fdpairs were declared as plain int arrays without _cleanup_close_pair_. If exec_shared_runtime_add() fails (e.g. OOM on hashmap_ensure_put), the already-opened fds are leaked. Since exec_shared_runtime_add() uses TAKE_FD on success, the array entries are reset to -1 after ownership transfer, so adding _cleanup_close_pair_ is safe and closes the fds only when they were never consumed. Signed-off-by: dongshengyuan --- src/core/execute.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/execute.c b/src/core/execute.c index c2e8bc82b7..4240e01d0b 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2748,7 +2748,8 @@ int exec_shared_runtime_deserialize_compat(Unit *u, const char *key, const char int exec_shared_runtime_deserialize_one(Manager *m, const char *value, FDSet *fds) { _cleanup_free_ char *tmp_dir = NULL, *var_tmp_dir = NULL; char *id = NULL; - int r, userns_fdpair[] = {-1, -1}, netns_fdpair[] = {-1, -1}, ipcns_fdpair[] = {-1, -1}; + _cleanup_close_pair_ int userns_fdpair[] = EBADF_PAIR, netns_fdpair[] = EBADF_PAIR, ipcns_fdpair[] = EBADF_PAIR; + int r; const char *p, *v = ASSERT_PTR(value); size_t n;