[systemd-devel] [PATCH 1/3] [file handle leak] Close file handle when we're done with it

David Herrmann dh.herrmann at gmail.com
Thu Sep 11 08:40:38 PDT 2014


Hi

On Wed, Sep 10, 2014 at 9:14 PM,  <philippedeswert at gmail.com> wrote:
> From: Philippe De Swert <philippedeswert at gmail.com>
>
> In test_read_one_char the filehandle does not get its fclose
> at the end of the function, thus we are leaking fd's.
>
> Found with Coverity. Fixes: CID#1237749
>
> Signed-off-by: Philippe De Swert <philippedeswert at gmail.com>
> ---
>  src/test/test-util.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/test/test-util.c b/src/test/test-util.c
> index 72a8a6b..0d36711 100644
> --- a/src/test/test-util.c
> +++ b/src/test/test-util.c
> @@ -947,6 +947,7 @@ static void test_read_one_char(void) {
>          assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
>
>          unlink(name);
> +        fclose(file);

This does not work. If you close "file", you also close the underlying
fd. Therefore, the _cleanup_close_ on "fd" will close it again. This
is fine here as we're single-threaded, but we should do it right. I
fixed it up by using _cleanup_fclose_.

Thanks
David

>  }
>
>  static void test_ignore_signals(void) {
> --
> 1.8.3.2
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list