Skip to content

Commit 02fbe65

Browse files
mniestrojcfriedt
authored andcommitted
logging: fs: fix leak of opened directories in check_log_file_exist()
Opened directory descriptor is leaked when returning 1. Fix that by utilizing goto in function return path. Fixes: 6b18e69 ("subsys/loggin/log_backend_fs: added recovery after file lost") Signed-off-by: Marcin Niestroj <[email protected]>
1 parent 80b406d commit 02fbe65

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

subsys/logging/log_backend_fs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ static int check_log_file_exist(int num)
119119
while (true) {
120120
rc = fs_readdir(&dir, &ent);
121121
if (rc < 0) {
122-
(void) fs_closedir(&dir);
123-
return -EIO;
122+
rc = -EIO;
123+
goto close_dir;
124124
}
125125
if (ent.name[0] == 0) {
126126
break;
@@ -129,13 +129,17 @@ static int check_log_file_exist(int num)
129129
rc = get_log_file_id(&ent);
130130

131131
if (rc == num) {
132-
return 1;
132+
rc = 1;
133+
goto close_dir;
133134
}
134135
}
135136

137+
rc = 0;
138+
139+
close_dir:
136140
(void) fs_closedir(&dir);
137141

138-
return 0;
142+
return rc;
139143
}
140144

141145
int write_log_to_file(uint8_t *data, size_t length, void *ctx)

0 commit comments

Comments
 (0)