daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From 69aaf3c41923fafd9616b1bbec51fa6bcb23b886 Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Sat, 7 Mar 2015 15:05:50 -0500
923a60
Subject: [PATCH] bus: fix leak in error path
923a60
923a60
CID #1271349.
923a60
923a60
Cherry-picked from: bcf88fc3f14867f1cabc911c27b661d738281df0
923a60
Related: #1331667
923a60
---
923a60
 src/libsystemd/sd-bus/bus-message.c | 9 ++++-----
923a60
 1 file changed, 4 insertions(+), 5 deletions(-)
923a60
923a60
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
923a60
index 2959303033..c8402a23a9 100644
923a60
--- a/src/libsystemd/sd-bus/bus-message.c
923a60
+++ b/src/libsystemd/sd-bus/bus-message.c
923a60
@@ -441,7 +441,7 @@ int bus_message_from_header(
923a60
                 size_t extra,
923a60
                 sd_bus_message **ret) {
923a60
 
923a60
-        sd_bus_message *m;
923a60
+        _cleanup_free_ sd_bus_message *m = NULL;
923a60
         struct bus_header *h;
923a60
         size_t a, label_sz;
923a60
 
923a60
@@ -460,15 +460,13 @@ int bus_message_from_header(
923a60
                 return -EBADMSG;
923a60
 
923a60
         h = header;
923a60
-        if (h->version != 1 &&
923a60
-            h->version != 2)
923a60
+        if (!IN_SET(h->version, 1, 2))
923a60
                 return -EBADMSG;
923a60
 
923a60
         if (h->type == _SD_BUS_MESSAGE_TYPE_INVALID)
923a60
                 return -EBADMSG;
923a60
 
923a60
-        if (h->endian != BUS_LITTLE_ENDIAN &&
923a60
-            h->endian != BUS_BIG_ENDIAN)
923a60
+        if (!IN_SET(h->endian, BUS_LITTLE_ENDIAN, BUS_BIG_ENDIAN))
923a60
                 return -EBADMSG;
923a60
 
923a60
         /* Note that we are happy with unknown flags in the flags header! */
923a60
@@ -557,6 +555,7 @@ int bus_message_from_header(
923a60
 
923a60
         m->bus = sd_bus_ref(bus);
923a60
         *ret = m;
923a60
+        m = NULL;
923a60
 
923a60
         return 0;
923a60
 }