From 06348103d6c0449b1864f7db7672ea969401ceba Mon Sep 17 00:00:00 2001 From: 3idey Date: Sun, 8 Feb 2026 12:36:49 +0200 Subject: [PATCH] fsnotify: Fix memory leak in pre_dump_one_inotify error path When irmap_queue_cache fails, the remaining inotify watch descriptors and the wd array are not freed, causing a memory leak. Add cleanup label to ensure proper deallocation of remaining entries and the wd array on error paths. Signed-off-by: 3idey --- criu/fsnotify.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/criu/fsnotify.c b/criu/fsnotify.c index dd468ecaa..55bae63bd 100644 --- a/criu/fsnotify.c +++ b/criu/fsnotify.c @@ -364,7 +364,7 @@ free: static int pre_dump_one_inotify(int pid, int lfd) { InotifyFileEntry ie = INOTIFY_FILE_ENTRY__INIT; - int i; + int i, ret = -1; if (parse_fdinfo_pid(pid, lfd, FD_TYPES__INOTIFY, &ie)) { pr_err("Failed to parse fdinfo for inotify (pid %d lfd %d)\n", pid, lfd); @@ -377,13 +377,18 @@ static int pre_dump_one_inotify(int pid, int lfd) if (irmap_queue_cache(we->s_dev, we->i_ino, we->f_handle)) { pr_err("Failed to queue irmap cache for inotify wd %#x (dev %#x ino %#" PRIx64 ")\n", we->wd, we->s_dev, we->i_ino); - return -1; + goto err; } xfree(we); } - return 0; + ret = 0; +err: + for (; i < ie.n_wd; i++) + xfree(ie.wd[i]); + xfree(ie.wd); + return ret; } const struct fdtype_ops inotify_dump_ops = {