]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: don't overallocate the message buffer
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 10 Apr 2026 08:52:21 +0000 (10:52 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 10 Apr 2026 11:20:16 +0000 (12:20 +0100)
newa(t, n) already allocates sizeof(t) * n bytes, so previously we'd
actually allocate sizeof(t) * sizeof(t) * n bytes, which is ~16x more
(on x86_64) that we actually needed.

This is probably an oversight from a tree-wide change in
6e9417f5b4f29938fab1eee2b5edf596cc580452 that replaced alloca() with
newa().

Follow-up for 6e9417f5b4f29938fab1eee2b5edf596cc580452.

src/libsystemd/sd-bus/bus-socket.c

index 3c5f596440ec913eaf3dd91f924d66260c6b4ef5..638d650336b11f7a94d2842c1a26cfa7226f1d2f 100644 (file)
@@ -1238,7 +1238,6 @@ int bus_socket_take_fd(sd_bus *b) {
 int bus_socket_write_message(sd_bus *bus, sd_bus_message *m, size_t *idx) {
         struct iovec *iov;
         ssize_t k;
-        size_t n;
         unsigned j;
         int r;
 
@@ -1254,9 +1253,8 @@ int bus_socket_write_message(sd_bus *bus, sd_bus_message *m, size_t *idx) {
         if (r < 0)
                 return r;
 
-        n = m->n_iovec * sizeof(struct iovec);
-        iov = newa(struct iovec, n);
-        memcpy_safe(iov, m->iovec, n);
+        iov = newa(struct iovec, m->n_iovec);
+        memcpy_safe(iov, m->iovec, sizeof(struct iovec) * m->n_iovec);
 
         j = 0;
         iovec_advance(iov, &j, *idx);