[systemd-devel] [systemd PATCH 2/2] Fix file descriptor leak in efi_get_variable()

Lennart Poettering lennart at poettering.net
Fri Jan 25 07:58:48 PST 2013


On Fri, 25.01.13 13:59, Thomas Jarosch (thomas.jarosch at intra2net.com) wrote:

> Detected by cppcheck.
> 
> Signed-off-by: Thomas Jarosch <thomas.jarosch at intra2net.com>
> ---
>  src/shared/efivars.c | 27 +++++++++++++++++++++------
>  1 file changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/src/shared/efivars.c b/src/shared/efivars.c
> index d5cb88c..4402aec 100644
> --- a/src/shared/efivars.c
> +++ b/src/shared/efivars.c
> @@ -53,30 +53,44 @@ int efi_get_variable(sd_id128_t vendor, const char *name, uint32_t *attribute, v
>          if (fd < 0)
>                  return -errno;
>  
> -        if (fstat(fd, &st) < 0)
> +        if (fstat(fd, &st) < 0) {
> +                close_nointr_nofail(fd);


I figure cppcheck needs to learn about _cleanup_close_... We use gcc's
cleanup attribute logic to close this file. In fact we make use of that
quite heavily now for memory and other kind of resourec allocation....

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list