[systemd-devel] [PATCH 1/3] core/socket: use _cleanup_free_

Shawn Landden shawn at churchofgit.com
Thu Nov 14 07:50:42 PST 2013


---
 src/core/socket.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/core/socket.c b/src/core/socket.c
index 03b8f92..f505e4f 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -1475,7 +1475,7 @@ static void socket_enter_running(Socket *s, int cfd) {
 
                 socket_set_state(s, SOCKET_RUNNING);
         } else {
-                char *prefix, *instance = NULL, *name;
+                _cleanup_free_ char *prefix = NULL, *instance = NULL, *name = NULL;
                 Service *service;
 
                 if (s->n_connections >= s->max_connections) {
@@ -1503,14 +1503,11 @@ static void socket_enter_running(Socket *s, int cfd) {
 
                 prefix = unit_name_to_prefix(UNIT(s)->id);
                 if (!prefix) {
-                        free(instance);
                         r = -ENOMEM;
                         goto fail;
                 }
 
                 name = unit_name_build(prefix, instance, ".service");
-                free(prefix);
-                free(instance);
 
                 if (!name) {
                         r = -ENOMEM;
@@ -1518,10 +1515,8 @@ static void socket_enter_running(Socket *s, int cfd) {
                 }
 
                 r = unit_add_name(UNIT_DEREF(s->service), name);
-                if (r < 0) {
-                        free(name);
+                if (r < 0)
                         goto fail;
-                }
 
                 service = SERVICE(UNIT_DEREF(s->service));
                 unit_ref_unset(&s->service);
@@ -1530,7 +1525,6 @@ static void socket_enter_running(Socket *s, int cfd) {
                 UNIT(service)->no_gc = false;
 
                 unit_choose_id(UNIT(service), name);
-                free(name);
 
                 r = service_set_socket_fd(service, cfd, s);
                 if (r < 0)
-- 
1.8.4.3



More information about the systemd-devel mailing list