diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 1224654290c71..f4ede985de797 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -1203,11 +1203,12 @@ static sd_event_source *source_new(sd_event *e, bool floating, EventSourceType t assert(type < _SOURCE_EVENT_SOURCE_TYPE_MAX); assert(size_table[type] > 0); - /* We use expand_to_usable() here to tell gcc that it should consider this an object of the full - * size, even if we only allocate the initial part we need. */ - s = expand_to_usable(malloc0(size_table[type]), sizeof(sd_event_source)); + s = malloc0(size_table[type]); if (!s) return NULL; + /* We use expand_to_usable() here to tell gcc that it should consider this an object of the full + * size, even if we only allocate the initial part we need. */ + s = expand_to_usable(s, sizeof(sd_event_source)); /* Note: we cannot use compound initialization here, because sizeof(sd_event_source) is likely larger * than what we allocated here. */