]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: use heap only when nwea() does not work 38878/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 19 Aug 2025 20:46:55 +0000 (05:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Sep 2025 10:20:50 +0000 (19:20 +0900)
Then, we can avoid malloc in most cases.

src/basic/fd-util.c

index 281cdfcc038c85786732e0149ab71778018f3c97..f1af57a3d0afd7b8887d8c513af348febc68778a 100644 (file)
@@ -410,7 +410,7 @@ int close_all_fds(const int except[], size_t n_except) {
         assert(n_except < SIZE_MAX);
         n_sorted = n_except + 1;
 
-        if (n_sorted > 64) /* Use heap for large numbers of fds, stack otherwise */
+        if (n_sorted > ALLOCA_MAX / sizeof(int)) /* Use heap for large numbers of fds, stack otherwise */
                 sorted = sorted_malloc = new(int, n_sorted);
         else
                 sorted = newa(int, n_sorted);