Skip to content

Commit 2a20154

Browse files
Ding Xiangl0kod
authored andcommitted
selftests/landlock: Fix a resource leak
The opened file should be closed before return, otherwise resource leak will occur. Signed-off-by: Ding Xiang <dingxiang@cmss.chinamobile.com> Link: https://lore.kernel.org/r/20230830101148.3738-1-dingxiang@cmss.chinamobile.com Fixes: 3de64b6 ("selftests/landlock: Add supports_filesystem() helper") Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 246c713 commit 2a20154

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tools/testing/selftests/landlock/fs_test.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static bool supports_filesystem(const char *const filesystem)
113113
{
114114
char str[32];
115115
int len;
116-
bool res;
116+
bool res = true;
117117
FILE *const inf = fopen("/proc/filesystems", "r");
118118

119119
/*
@@ -125,14 +125,16 @@ static bool supports_filesystem(const char *const filesystem)
125125

126126
/* filesystem can be null for bind mounts. */
127127
if (!filesystem)
128-
return true;
128+
goto out;
129129

130130
len = snprintf(str, sizeof(str), "nodev\t%s\n", filesystem);
131131
if (len >= sizeof(str))
132132
/* Ignores too-long filesystem names. */
133-
return true;
133+
goto out;
134134

135135
res = fgrep(inf, str);
136+
137+
out:
136138
fclose(inf);
137139
return res;
138140
}

0 commit comments

Comments
 (0)