On Fri, Dec 18, 2020 at 08:09:23PM +0100, Andrea Claudi wrote: > Functions get_cgroup2_id() and get_cgroup2_path() uncorrectly performs > cleanup on the single return point. Both of them may get to use close() > with a negative argument, if open() fails. > > Fix this adding proper labels and gotos to make sure we clean up only > resources we are effectively used before.
Since free(NULL) is OK according to POSIX, the fds are initialized to -1 and open() returns -1 on error, you may simplify these changes down to making the close() calls conditional: | if (fd >= 0) | close(fd); Cheers, Phil