Coverage Report

Created: 2026-05-23 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ostree/libglnx/glnx-local-alloc.h
Line
Count
Source
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2
 *
3
 * Copyright (C) 2012,2015 Colin Walters <walters@verbum.org>.
4
 * SPDX-License-Identifier: LGPL-2.0-or-later
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the
18
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
 * Boston, MA 02111-1307, USA.
20
 */
21
22
#pragma once
23
24
#include <gio/gio.h>
25
#include <errno.h>
26
27
#include "glnx-backports.h"
28
29
G_BEGIN_DECLS
30
31
/**
32
 * glnx_unref_object:
33
 *
34
 * Call g_object_unref() on a variable location when it goes out of
35
 * scope.  Note that unlike g_object_unref(), the variable may be
36
 * %NULL.
37
 */
38
#define glnx_unref_object __attribute__ ((cleanup(glnx_local_obj_unref)))
39
static inline void
40
glnx_local_obj_unref (void *v)
41
0
{
42
0
  GObject *o = *(GObject **)v;
43
0
  if (o)
44
0
    g_object_unref (o);
45
0
}
Unexecuted instantiation: fuzz-bootconfig.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-bootconfig-parser.c:glnx_local_obj_unref
Unexecuted instantiation: ot-gio-utils.c:glnx_local_obj_unref
Unexecuted instantiation: glnx-fdio.c:glnx_local_obj_unref
Unexecuted instantiation: glnx-xattrs.c:glnx_local_obj_unref
Unexecuted instantiation: glnx-dirfd.c:glnx_local_obj_unref
Unexecuted instantiation: glnx-shutil.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-core.c:glnx_local_obj_unref
Unexecuted instantiation: ot-checksum-utils.c:glnx_local_obj_unref
Unexecuted instantiation: ot-fs-utils.c:glnx_local_obj_unref
Unexecuted instantiation: ot-unix-utils.c:glnx_local_obj_unref
Unexecuted instantiation: ot-variant-utils.c:glnx_local_obj_unref
Unexecuted instantiation: fuzz-repo.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-commit.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-composefs.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-pull.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-refs.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-verity.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-file.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-sepolicy.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-sysroot.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-sysroot-cleanup.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-sysroot-deploy.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-deployment.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-bootloader.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-bootloader-aboot.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-bootloader-grub2.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-bootloader-zipl.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-bootloader-syslinux.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-bootloader-uboot.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-static-delta-core.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-static-delta-processing.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-kernel-args.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-gpg-verifier.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-gpg-verify-result.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-sign.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-sign-dummy.c:glnx_local_obj_unref
Unexecuted instantiation: ot-checksum-instream.c:glnx_local_obj_unref
Unexecuted instantiation: ot-gpg-utils.c:glnx_local_obj_unref
Unexecuted instantiation: ot-keyfile-utils.c:glnx_local_obj_unref
Unexecuted instantiation: ot-tool-util.c:glnx_local_obj_unref
Unexecuted instantiation: otcore-prepare-root.c:glnx_local_obj_unref
Unexecuted instantiation: glnx-lockfile.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-async-progress.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-content-writer.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-linuxfsutil.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-diff.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-mutable-tree.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-ref.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-remote.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-checkout.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-prune.c:glnx_local_obj_unref
Unexecuted instantiation: ostree-repo-traverse.c:glnx_local_obj_unref
Unexecuted instantiation: fuzz-bsdiff.c:glnx_local_obj_unref
46
0
#define glnx_unref_object __attribute__ ((cleanup(glnx_local_obj_unref)))
47
48
/* Backwards-compat with older libglnx */
49
0
#define glnx_steal_fd g_steal_fd
50
51
/**
52
 * glnx_close_fd:
53
 * @fdp: Pointer to fd
54
 *
55
 * Effectively `close (g_steal_fd (&fd))`.  Also
56
 * asserts that `close()` did not raise `EBADF` - encountering
57
 * that error is usually a critical bug in the program.
58
 */
59
static inline void
60
glnx_close_fd (int *fdp)
61
6.62k
{
62
6.62k
  int errsv;
63
64
6.62k
  g_assert (fdp);
65
66
6.62k
  int fd = g_steal_fd (fdp);
67
6.62k
  if (fd >= 0)
68
2.62k
    {
69
2.62k
      errsv = errno;
70
2.62k
      if (close (fd) < 0)
71
2.62k
        g_assert (errno != EBADF);
72
2.62k
      errno = errsv;
73
2.62k
    }
74
6.62k
}
Unexecuted instantiation: fuzz-bootconfig.c:glnx_close_fd
Unexecuted instantiation: ostree-bootconfig-parser.c:glnx_close_fd
Unexecuted instantiation: ot-gio-utils.c:glnx_close_fd
glnx-fdio.c:glnx_close_fd
Line
Count
Source
61
3.88k
{
62
3.88k
  int errsv;
63
64
3.88k
  g_assert (fdp);
65
66
3.88k
  int fd = g_steal_fd (fdp);
67
3.88k
  if (fd >= 0)
68
1.94k
    {
69
1.94k
      errsv = errno;
70
1.94k
      if (close (fd) < 0)
71
1.94k
        g_assert (errno != EBADF);
72
1.94k
      errno = errsv;
73
1.94k
    }
74
3.88k
}
Unexecuted instantiation: glnx-xattrs.c:glnx_close_fd
glnx-dirfd.c:glnx_close_fd
Line
Count
Source
61
1.50k
{
62
1.50k
  int errsv;
63
64
1.50k
  g_assert (fdp);
65
66
1.50k
  int fd = g_steal_fd (fdp);
67
1.50k
  if (fd >= 0)
68
137
    {
69
137
      errsv = errno;
70
137
      if (close (fd) < 0)
71
137
        g_assert (errno != EBADF);
72
137
      errno = errsv;
73
137
    }
74
1.50k
}
glnx-shutil.c:glnx_close_fd
Line
Count
Source
61
137
{
62
137
  int errsv;
63
64
137
  g_assert (fdp);
65
66
137
  int fd = g_steal_fd (fdp);
67
137
  if (fd >= 0)
68
0
    {
69
0
      errsv = errno;
70
0
      if (close (fd) < 0)
71
0
        g_assert (errno != EBADF);
72
0
      errno = errsv;
73
0
    }
74
137
}
Unexecuted instantiation: ostree-core.c:glnx_close_fd
Unexecuted instantiation: ot-checksum-utils.c:glnx_close_fd
Unexecuted instantiation: ot-fs-utils.c:glnx_close_fd
Unexecuted instantiation: ot-unix-utils.c:glnx_close_fd
Unexecuted instantiation: ot-variant-utils.c:glnx_close_fd
Unexecuted instantiation: fuzz-repo.c:glnx_close_fd
ostree-repo.c:glnx_close_fd
Line
Count
Source
61
1.09k
{
62
1.09k
  int errsv;
63
64
1.09k
  g_assert (fdp);
65
66
1.09k
  int fd = g_steal_fd (fdp);
67
1.09k
  if (fd >= 0)
68
548
    {
69
548
      errsv = errno;
70
548
      if (close (fd) < 0)
71
548
        g_assert (errno != EBADF);
72
548
      errno = errsv;
73
548
    }
74
1.09k
}
Unexecuted instantiation: ostree-repo-commit.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-composefs.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-pull.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-refs.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-verity.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-file.c:glnx_close_fd
Unexecuted instantiation: ostree-sepolicy.c:glnx_close_fd
Unexecuted instantiation: ostree-sysroot.c:glnx_close_fd
Unexecuted instantiation: ostree-sysroot-cleanup.c:glnx_close_fd
Unexecuted instantiation: ostree-sysroot-deploy.c:glnx_close_fd
Unexecuted instantiation: ostree-deployment.c:glnx_close_fd
Unexecuted instantiation: ostree-bootloader.c:glnx_close_fd
Unexecuted instantiation: ostree-bootloader-aboot.c:glnx_close_fd
Unexecuted instantiation: ostree-bootloader-grub2.c:glnx_close_fd
Unexecuted instantiation: ostree-bootloader-zipl.c:glnx_close_fd
Unexecuted instantiation: ostree-bootloader-syslinux.c:glnx_close_fd
Unexecuted instantiation: ostree-bootloader-uboot.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-static-delta-core.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-static-delta-processing.c:glnx_close_fd
Unexecuted instantiation: ostree-kernel-args.c:glnx_close_fd
Unexecuted instantiation: ostree-gpg-verifier.c:glnx_close_fd
Unexecuted instantiation: ostree-gpg-verify-result.c:glnx_close_fd
Unexecuted instantiation: ostree-sign.c:glnx_close_fd
Unexecuted instantiation: ostree-sign-dummy.c:glnx_close_fd
Unexecuted instantiation: ot-checksum-instream.c:glnx_close_fd
Unexecuted instantiation: ot-gpg-utils.c:glnx_close_fd
Unexecuted instantiation: ot-keyfile-utils.c:glnx_close_fd
Unexecuted instantiation: ot-tool-util.c:glnx_close_fd
Unexecuted instantiation: otcore-prepare-root.c:glnx_close_fd
Unexecuted instantiation: glnx-lockfile.c:glnx_close_fd
Unexecuted instantiation: ostree-async-progress.c:glnx_close_fd
Unexecuted instantiation: ostree-content-writer.c:glnx_close_fd
Unexecuted instantiation: ostree-linuxfsutil.c:glnx_close_fd
Unexecuted instantiation: ostree-diff.c:glnx_close_fd
Unexecuted instantiation: ostree-mutable-tree.c:glnx_close_fd
Unexecuted instantiation: ostree-ref.c:glnx_close_fd
Unexecuted instantiation: ostree-remote.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-checkout.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-prune.c:glnx_close_fd
Unexecuted instantiation: ostree-repo-traverse.c:glnx_close_fd
Unexecuted instantiation: fuzz-bsdiff.c:glnx_close_fd
75
76
/**
77
 * glnx_fd_close:
78
 *
79
 * Deprecated in favor of `glnx_autofd`.
80
 */
81
0
#define glnx_fd_close __attribute__((cleanup(glnx_close_fd)))
82
/**
83
 * glnx_autofd:
84
 *
85
 * Call close() on a variable location when it goes out of scope.
86
 */
87
4.69k
#define glnx_autofd __attribute__((cleanup(glnx_close_fd)))
88
89
G_END_DECLS