• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 22880772011

09 Mar 2026 07:31PM UTC coverage: 72.491% (+0.1%) from 72.368%
22880772011

push

github

web-flow
mount: honor --timeout-idle-sec=SEC option (#41010)

When using systemd-mount to create a transient .mount/.automount file
for removable storage, the option to specify the idle timeout on the
commandline using **--timeout-idle-sec=SEC** is not reflected in the
generated .automount file. Instead, the idle timeout is always set to 1
second.

arg_timeout_idle_set was never set to true when passing the argument, so
arg_timeout_idle was always set to 1s.

Fixes #41007.

Co-authored-by: patrick <patrick@localhost>

1 of 1 new or added line in 1 file covered. (100.0%)

1010 existing lines in 58 files now uncovered.

315636 of 435417 relevant lines covered (72.49%)

1246194.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.7
/src/basic/alloc-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <malloc.h>
4

5
#include "alloc-util.h"
6

7
void* memdup(const void *p, size_t l) {
598,631✔
8
        void *ret;
598,631✔
9

10
        assert(l == 0 || p);
598,631✔
11

12
        ret = malloc(l ?: 1);
598,631✔
13
        if (!ret)
598,631✔
14
                return NULL;
15

16
        return memcpy_safe(ret, p, l);
598,631✔
17
}
18

19
void* memdup_suffix0(const void *p, size_t l) {
3,473,681✔
20
        void *ret;
3,473,681✔
21

22
        assert(l == 0 || p);
3,473,681✔
23

24
        /* The same as memdup() but place a safety NUL byte after the allocated memory */
25

26
        if (_unlikely_(l == SIZE_MAX)) /* prevent overflow */
3,473,681✔
27
                return NULL;
28

29
        ret = malloc(l + 1);
3,473,681✔
30
        if (!ret)
3,473,681✔
31
                return NULL;
32

33
        ((uint8_t*) ret)[l] = 0;
3,473,681✔
34
        return memcpy_safe(ret, p, l);
3,473,681✔
35
}
36

37
size_t malloc_sizeof_safe(void **xp) {
601,633,832✔
38
        if (_unlikely_(!xp || !*xp))
601,633,832✔
39
                return 0;
40

41
        size_t sz = malloc_usable_size(*xp);
601,216,032✔
42
        *xp = expand_to_usable(*xp, sz);
601,216,032✔
43
        /* GCC doesn't see the _returns_nonnull_ when built with ubsan, so yet another hint to make it doubly
44
         * clear that expand_to_usable won't return NULL.
45
         * See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79265 */
46
        if (!*xp)
601,216,032✔
UNCOV
47
                assert_not_reached();
×
48
        return sz;
49
}
50

51
void* expand_to_usable(void *ptr, size_t newsize _unused_) {
602,324,413✔
52
        return ptr;
602,324,413✔
53
}
54

55
void* realloc0(void *p, size_t new_size) {
64,119✔
56
        size_t old_size;
64,119✔
57
        void *q;
64,119✔
58

59
        /* Like realloc(), but initializes anything appended to zero */
60

61
        old_size = MALLOC_SIZEOF_SAFE(p);
64,119✔
62

63
        q = realloc(p, new_size);
64,119✔
64
        if (!q)
64,119✔
65
                return NULL;
64,119✔
66

67
        new_size = MALLOC_SIZEOF_SAFE(q); /* Update with actually allocated space */
64,119✔
68

69
        if (new_size > old_size)
64,119✔
70
                memset((uint8_t*) q + old_size, 0, new_size - old_size);
58,512✔
71

72
        return q;
64,119✔
73
}
74

75
void* greedy_realloc(
608,534,258✔
76
                void **p,
77
                size_t need,
78
                size_t size) {
79

80
        size_t newalloc;
608,534,258✔
81
        void *q;
608,534,258✔
82

83
        assert(p);
608,534,258✔
84

85
        /* We use malloc_usable_size() for determining the current allocated size. On all systems we care
86
         * about this should be safe to rely on. Should there ever arise the need to avoid relying on this we
87
         * can instead locally fall back to realloc() on every call, rounded up to the next exponent of 2 or
88
         * so. */
89

90
        if (*p && (size == 0 || (MALLOC_SIZEOF_SAFE(*p) / size >= need)))
608,534,258✔
91
                return *p;
576,306,258✔
92

93
        if (_unlikely_(need > SIZE_MAX/2)) /* Overflow check */
32,228,000✔
94
                return NULL;
95
        newalloc = need * 2;
32,228,000✔
96

97
        if (!MUL_ASSIGN_SAFE(&newalloc, size))
32,228,000✔
98
                return NULL;
99

100
        if (newalloc < 64) /* Allocate at least 64 bytes */
32,228,000✔
101
                newalloc = 64;
27,041,025✔
102

103
        q = realloc(*p, newalloc);
32,228,000✔
104
        if (!q)
32,228,000✔
105
                return NULL;
106

107
        return *p = q;
32,228,000✔
108
}
109

110
void* greedy_realloc0(
4,307,560✔
111
                void **p,
112
                size_t need,
113
                size_t size) {
114

115
        size_t before, after;
4,307,560✔
116
        uint8_t *q;
4,307,560✔
117

118
        assert(p);
4,307,560✔
119

120
        before = MALLOC_SIZEOF_SAFE(*p); /* malloc_usable_size() will return 0 on NULL input, as per docs */
4,307,560✔
121

122
        q = greedy_realloc(p, need, size);
4,307,560✔
123
        if (!q)
4,307,560✔
124
                return NULL;
4,307,560✔
125

126
        after = MALLOC_SIZEOF_SAFE(q);
4,307,560✔
127

128
        if (size == 0) /* avoid division by zero */
4,307,560✔
129
                before = 0;
130
        else
131
                before = (before / size) * size; /* Round down */
4,307,560✔
132

133
        if (after > before)
4,307,560✔
134
                memzero(q + before, after - before);
2,360,652✔
135

136
        return q;
4,307,560✔
137
}
138

139
void* greedy_realloc_append(
14,704✔
140
                void **p,
141
                size_t *n_p,
142
                const void *from,
143
                size_t n_from,
144
                size_t size) {
145

146
        uint8_t *q;
14,704✔
147

148
        assert(p);
14,704✔
149
        assert(n_p);
14,704✔
150
        assert(from || n_from == 0);
14,704✔
151

152
        if (n_from > SIZE_MAX - *n_p)
14,704✔
153
                return NULL;
154

155
        q = greedy_realloc(p, *n_p + n_from, size);
14,704✔
156
        if (!q)
14,704✔
157
                return NULL;
158

159
        memcpy_safe(q + *n_p * size, from, n_from * size);
14,704✔
160

161
        *n_p += n_from;
14,704✔
162

163
        return q;
14,704✔
164
}
165

166
void free_many(void **p, size_t n) {
88,681✔
167
        assert(p || n == 0);
88,681✔
168

169
        FOREACH_ARRAY(i, p, n)
1,411,037✔
170
                *i = mfree(*i);
1,322,356✔
171
}
88,681✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc