Skip to content

Commit 7c2ec43

Browse files
bulwahnmasahir0y
authored andcommitted
fixdep: exit with error code in error branches of do_config_file()
do_config_file() should exit with an error code on internal run-time errors, and not return if it fails as then the error in do_config_file() would go unnoticed in the current code and allow the build to continue. The exit with error code will make the build fail in those very exceptional cases. If this occurs, this actually indicates a deeper problem in the execution of the kernel build process. Now, in these error cases, we do not explicitly free memory and close the file handlers in do_config_file(), as this is covered by exit(). This issue in the fixdep script was introduced with its initial implementation back in 2002 by the original author Kai Germaschewski with this commit 04bd721 ("kbuild: Make dependencies at compile time") in the linux history git tree, i.e., git://git.kernel.org/pub/scm/linux/kernel/git/history/history.git. This issue was identified during the review of a previous patch that intended to address a memory leak detected by a static analysis tool. Link: https://lkml.org/lkml/2017/12/14/736 Suggested-by: Nicholas Mc Guire <der.herr@hofr.at> Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent ae64f9b commit 7c2ec43

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎scripts/basic/fixdep.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,11 @@ static void do_config_file(const char *filename)
290290
map = malloc(st.st_size + 1);
291291
if (!map) {
292292
perror("fixdep: malloc");
293-
close(fd);
294-
return;
293+
exit(2);
295294
}
296295
if (read(fd, map, st.st_size) != st.st_size) {
297296
perror("fixdep: read");
298-
close(fd);
299-
return;
297+
exit(2);
300298
}
301299
map[st.st_size] = '\0';
302300
close(fd);

0 commit comments

Comments
 (0)