[systemd-commits] 2 commits - src/libsystemd

Lennart Poettering lennart at kemper.freedesktop.org
Thu May 14 13:41:32 PDT 2015


 src/libsystemd/sd-bus/test-bus-chat.c |   36 ++++++++++------------------------
 1 file changed, 11 insertions(+), 25 deletions(-)

New commits:
commit 0e85114376b7d28c79d0a66996d1bc1a1ee01724
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu May 14 22:41:19 2015 +0200

    test-bus-chat: various modernizations

diff --git a/src/libsystemd/sd-bus/test-bus-chat.c b/src/libsystemd/sd-bus/test-bus-chat.c
index 1e50dfc..046e999 100644
--- a/src/libsystemd/sd-bus/test-bus-chat.c
+++ b/src/libsystemd/sd-bus/test-bus-chat.c
@@ -263,10 +263,10 @@ fail:
 static void* client1(void*p) {
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_close_unref_ sd_bus *bus = NULL;
-        sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         const char *hello;
         int r;
-        int pp[2] = { -1, -1 };
+        _cleanup_close_pair_ int pp[2] = { -1, -1 };
         char x;
 
         r = sd_bus_open_user(&bus);
@@ -347,10 +347,6 @@ finish:
 
         }
 
-        sd_bus_error_free(&error);
-
-        safe_close_pair(pp);
-
         return INT_TO_PTR(r);
 }
 
@@ -365,8 +361,8 @@ static int quit_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_er
 
 static void* client2(void*p) {
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
-        sd_bus *bus = NULL;
-        sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_bus_close_unref_ sd_bus *bus = NULL;
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         bool quit = false;
         const char *mid;
         int r;
@@ -395,8 +391,7 @@ static void* client2(void*p) {
                 goto finish;
         }
 
-        sd_bus_message_unref(m);
-        m = NULL;
+        m = sd_bus_message_unref(m);
 
         r = sd_bus_message_new_signal(
                         bus,
@@ -415,8 +410,7 @@ static void* client2(void*p) {
                 goto finish;
         }
 
-        sd_bus_message_unref(m);
-        m = NULL;
+        m = sd_bus_message_unref(m);
 
         r = sd_bus_message_new_method_call(
                         bus,
@@ -444,8 +438,7 @@ static void* client2(void*p) {
 
         log_info("Machine ID is %s.", mid);
 
-        sd_bus_message_unref(m);
-        m = NULL;
+        m = sd_bus_message_unref(m);
 
         r = sd_bus_message_new_method_call(
                         bus,
@@ -459,8 +452,7 @@ static void* client2(void*p) {
                 goto finish;
         }
 
-        sd_bus_message_unref(reply);
-        reply = NULL;
+        reply = sd_bus_message_unref(reply);
 
         r = sd_bus_call(bus, m, 200 * USEC_PER_MSEC, &error, &reply);
         if (r < 0)
@@ -468,8 +460,7 @@ static void* client2(void*p) {
         else
                 log_info("Slow call succeed.");
 
-        sd_bus_message_unref(m);
-        m = NULL;
+        m = sd_bus_message_unref(m);
 
         r = sd_bus_message_new_method_call(
                         bus,
@@ -522,12 +513,9 @@ finish:
                         goto finish;
                 }
 
-                sd_bus_send(bus, q, NULL);
-                sd_bus_flush(bus);
-                sd_bus_unref(bus);
+                (void) sd_bus_send(bus, q, NULL);
         }
 
-        sd_bus_error_free(&error);
         return INT_TO_PTR(r);
 }
 

commit 2f50a2d55bf0a8b5959a6864ae1b39e7e9e0ce08
Author: Cristian Rodríguez <crrodriguez at opensuse.org>
Date:   Sat May 9 22:14:09 2015 -0300

    sd-bus: fix memory leak in test-bus-chat
    
    Building with address sanitizer enabled on GCC 5.1.x a memory leak
    is reported because we never close the bus, fix it by using
    cleanup variable attribute.

diff --git a/src/libsystemd/sd-bus/test-bus-chat.c b/src/libsystemd/sd-bus/test-bus-chat.c
index 99261fa..1e50dfc 100644
--- a/src/libsystemd/sd-bus/test-bus-chat.c
+++ b/src/libsystemd/sd-bus/test-bus-chat.c
@@ -262,7 +262,7 @@ fail:
 
 static void* client1(void*p) {
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
-        sd_bus *bus = NULL;
+        _cleanup_bus_close_unref_ sd_bus *bus = NULL;
         sd_bus_error error = SD_BUS_ERROR_NULL;
         const char *hello;
         int r;
@@ -345,8 +345,6 @@ finish:
                 else
                         sd_bus_send(bus, q, NULL);
 
-                sd_bus_flush(bus);
-                sd_bus_unref(bus);
         }
 
         sd_bus_error_free(&error);



More information about the systemd-commits mailing list