Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kselftests: cgroup: Avoid the reuse of fd after it is deallocated

It is necessary to set fd to -1 when inotify_add_watch() fails in
cg_prepare_for_wait. Otherwise the fd which has been closed in
cg_prepare_for_wait may be misused in other functions such as
cg_enter_and_wait_for_frozen and cg_freeze_wait.

Fixes: 5313bfe425c8 ("selftests: cgroup: add freezer controller self-tests")
Signed-off-by: Hewenliang <hewenliang4@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Hewenliang and committed by
Tejun Heo
d671fa63 742e8cd3

+1
+1
tools/testing/selftests/cgroup/test_freezer.c
··· 72 72 if (ret == -1) { 73 73 debug("Error: inotify_add_watch() failed\n"); 74 74 close(fd); 75 + fd = -1; 75 76 } 76 77 77 78 return fd;