chiark / gitweb /
bus: fix leak in error path
[elogind.git] / src / libsystemd / sd-bus / bus-message.c
index 295930303306704daff28a3c50cfb91d836d4045..7eac069e980256c352108d9eb7419f5d1df7280d 100644 (file)
@@ -27,7 +27,6 @@
 #include "utf8.h"
 #include "strv.h"
 #include "time-util.h"
-#include "cgroup-util.h"
 #include "memfd-util.h"
 
 #include "sd-bus.h"
@@ -441,7 +440,7 @@ int bus_message_from_header(
                 size_t extra,
                 sd_bus_message **ret) {
 
-        sd_bus_message *m;
+        _cleanup_free_ sd_bus_message *m = NULL;
         struct bus_header *h;
         size_t a, label_sz;
 
@@ -460,15 +459,13 @@ int bus_message_from_header(
                 return -EBADMSG;
 
         h = header;
-        if (h->version != 1 &&
-            h->version != 2)
+        if (!IN_SET(h->version, 1, 2))
                 return -EBADMSG;
 
         if (h->type == _SD_BUS_MESSAGE_TYPE_INVALID)
                 return -EBADMSG;
 
-        if (h->endian != BUS_LITTLE_ENDIAN &&
-            h->endian != BUS_BIG_ENDIAN)
+        if (!IN_SET(h->endian, BUS_LITTLE_ENDIAN, BUS_BIG_ENDIAN))
                 return -EBADMSG;
 
         /* Note that we are happy with unknown flags in the flags header! */
@@ -557,6 +554,7 @@ int bus_message_from_header(
 
         m->bus = sd_bus_ref(bus);
         *ret = m;
+        m = NULL;
 
         return 0;
 }
@@ -634,6 +632,9 @@ static sd_bus_message *message_new(sd_bus *bus, uint8_t type) {
         m->root_container.need_offsets = BUS_MESSAGE_IS_GVARIANT(m);
         m->bus = sd_bus_ref(bus);
 
+        if (bus->allow_interactive_authorization)
+                m->header->flags |= BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
+
         return m;
 }