chiark / gitweb /
tree-wide: use TAKE_PTR() and TAKE_FD() macros
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 5 Apr 2018 05:26:26 +0000 (14:26 +0900)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
20 files changed:
src/basic/cgroup-util.c
src/basic/fileio.c
src/basic/hexdecoct.c
src/basic/khash.c
src/basic/locale-util.c
src/basic/socket-util.c
src/basic/time-util.c
src/libelogind/sd-bus/bus-control.c
src/libelogind/sd-bus/bus-creds.c
src/libelogind/sd-bus/bus-match.c
src/libelogind/sd-bus/bus-message.c
src/libelogind/sd-bus/sd-bus.c
src/libelogind/sd-login/sd-login.c
src/login/logind-seat-dbus.c
src/login/logind-session-dbus.c
src/login/logind-user-dbus.c
src/login/logind-user.c
src/shared/acl-util.c
src/shared/bus-util.c
src/shared/conf-parser.c

index 11d9795291f6859036762c7241b9a3086e68ae82..d9c5fdc9aee6c6828bd0cc5389eb0adbc2cd9231 100644 (file)
@@ -2562,8 +2562,7 @@ int cg_kernel_controllers(Set **ret) {
                         return r;
         }
 
-        *ret = controllers;
-        controllers = NULL;
+        *ret = TAKE_PTR(controllers);
 
         return 0;
 }
index dd8fb1fcb22ca7fcfc689257a9961b3f2f4404ba..855f9a7809dccc3cec868d2abf67bf2ff2a7f226 100644 (file)
@@ -1618,8 +1618,7 @@ int read_line(FILE *f, size_t limit, char **ret) {
         if (ret) {
                 buffer[n] = 0;
 
-                *ret = buffer;
-                buffer = NULL;
+                *ret = TAKE_PTR(buffer);
         }
 
         return (int) count;
index 0764521b6ff006921ac10191a40e75f229f8c80d..7f8a74acf6a2fc7857715794635658631376fd6c 100644 (file)
@@ -125,8 +125,7 @@ int unhexmem(const char *p, size_t l, void **mem, size_t *len) {
 
         *z = 0;
 
-        *mem = r;
-        r = NULL;
+        *mem = TAKE_PTR(r);
         *len = (l + 1) / 2;
 
         return 0;
@@ -482,8 +481,7 @@ int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *_l
 
         *z = 0;
 
-        *mem = r;
-        r = NULL;
+        *mem = TAKE_PTR(r);
         *_len = len;
 
         return 0;
@@ -751,8 +749,7 @@ int unbase64mem(const char *p, size_t l, void **ret, size_t *ret_size) {
         if (ret_size)
                 *ret_size = (size_t) (z - buf);
 
-        *ret = buf;
-        buf = NULL;
+        *ret = TAKE_PTR(buf);
 
         return 0;
 }
index 6463faf3e12ac72a5b9e3edb59765b2fdb1a2fce..b3e1dc444840d05691022f7cb00b3d5fabe851eb 100644 (file)
@@ -216,8 +216,7 @@ int khash_dup(khash *h, khash **ret) {
         if (copy->fd < 0)
                 return -errno;
 
-        *ret = copy;
-        copy = NULL;
+        *ret = TAKE_PTR(copy);
 
         return 0;
 }
index de3d7c8c89100ee1ab26f5c9e3186cb3101ed411..2080be24be5197fe5b0a27384a5a215a82c93dad 100644 (file)
@@ -196,8 +196,7 @@ int get_locales(char ***ret) {
 
         strv_sort(l);
 
-        *ret = l;
-        l = NULL;
+        *ret = TAKE_PTR(l);
 
         return 0;
 }
index 23a5337003c5a616fa929014db2e80c8e15c383d..dcfa0e0d86ebe45c44a26102c241299e3e0e362c 100644 (file)
@@ -1043,8 +1043,7 @@ int getpeergroups(int fd, gid_t **ret) {
         if ((socklen_t) (int) n != n)
                 return -E2BIG;
 
-        *ret = d;
-        d = NULL;
+        *ret = TAKE_PTR(d);
 
         return (int) n;
 }
index dc387d8b7ff8a959d4223262fec5458b792a35e2..f79d08ca8b757446bb2b6afe82aabae89fa89059 100644 (file)
@@ -1298,8 +1298,7 @@ int get_timezones(char ***ret) {
         } else if (errno != ENOENT)
                 return -errno;
 
-        *ret = zones;
-        zones = NULL;
+        *ret = TAKE_PTR(zones);
 
         return 0;
 }
index 9dd5274bf60339dd412aa4fb5fc85ad1e9eaafb9..50f2b3fc1afc65e9b728ac33786c26b885d4bfea 100644 (file)
@@ -431,14 +431,11 @@ _public_ int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatabl
                 if (r < 0)
                         return r;
 
-                *activatable = y;
-                y = NULL;
+                *activatable = TAKE_PTR(y);
         }
 
-        if (acquired) {
-                *acquired = x;
-                x = NULL;
-        }
+        if (acquired)
+                *acquired = TAKE_PTR(x);
 
         return 0;
 }
@@ -734,10 +731,8 @@ _public_ int sd_bus_get_name_creds(
                         return r;
         }
 
-        if (creds) {
-                *creds = c;
-                c = NULL;
-        }
+        if (creds)
+                *creds = TAKE_PTR(c);
 
         return 0;
 }
@@ -810,8 +805,8 @@ _public_ int sd_bus_get_owner_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **r
         if (r < 0)
                 return r;
 
-        *ret = c;
-        c = NULL;
+        *ret = TAKE_PTR(c);
+
         return 0;
 }
 
index add32c6b2d893039d861debb87bdb4e0fab56e02..308e8dc543573432406da5c603c199182c099d89 100644 (file)
@@ -1351,7 +1351,7 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret)
         if (r < 0)
                 return r;
 
-        *ret = n;
-        n = NULL;
+        *ret = TAKE_PTR(n);
+
         return 0;
 }
index bd78ccb699fa679f437a1217e60285325957d2a9..82b29af8b5e18454cd94e4a1e549f99dc848d123 100644 (file)
@@ -903,11 +903,10 @@ int bus_match_parse(
                 }
 
                 components[n_components].type = t;
-                components[n_components].value_str = value;
+                components[n_components].value_str = TAKE_PTR(value);
                 components[n_components].value_u8 = u;
                 n_components++;
 
-                value = NULL;
 
                 if (q[quoted] == 0)
                         break;
index 7bdaaaad6e1cfa095e8a0c8431e43d6d1683c170..cf8008bda4cac49ffa630f774d76a6e5f534b376 100644 (file)
@@ -513,8 +513,7 @@ int bus_message_from_header(
         }
 
         m->bus = sd_bus_ref(bus);
-        *ret = m;
-        m = NULL;
+        *ret = TAKE_PTR(m);
 
         return 0;
 }
@@ -5871,8 +5870,7 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
                 return r;
 
         sd_bus_message_unref(*m);
-        *m = n;
-        n = NULL;
+        *m = TAKE_PTR(n);
 
         return 0;
 }
index c5013f98c293652b4a7e02ba4839b18710ce1e10..71a96ac006bd05b467250c19b930dd57589e3933 100644 (file)
@@ -527,8 +527,7 @@ static int synthesize_connected_signal(sd_bus *bus) {
 
         /* Insert at the very front */
         memmove(bus->rqueue + 1, bus->rqueue, sizeof(sd_bus_message*) * bus->rqueue_size);
-        bus->rqueue[0] = m;
-        m = NULL;
+        bus->rqueue[0] = TAKE_PTR(m);
         bus->rqueue_size++;
 
         return 0;
@@ -2788,8 +2787,8 @@ static int process_running(sd_bus *bus, bool hint_priority, int64_t priority, sd
                 if (r < 0)
                         return r;
 
-                *ret = m;
-                m = NULL;
+                *ret = TAKE_PTR(m);
+
                 return 1;
         }
 
@@ -2948,10 +2947,8 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
         bus->exit_triggered = true;
         (void) bus_exit_now(bus);
 
-        if (ret) {
-                *ret = m;
-                m = NULL;
-        }
+        if (ret)
+                *ret = TAKE_PTR(m);
 
         r = 1;
 
index 490a56a9466ea6da9908f9a0bd4e33fa4b4df78e..f47a8a1b8192c826fd851d49116bcc835ddff8d2 100644 (file)
@@ -771,15 +771,11 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
 
         r = strv_length(a);
 
-        if (sessions) {
-                *sessions = a;
-                a = NULL;
-        }
+        if (sessions)
+                *sessions = TAKE_PTR(a);
 
-        if (uids) {
-                *uids = b;
-                b = NULL;
-        }
+        if (uids)
+                *uids = TAKE_PTR(b);
 
         if (n_uids)
                 *n_uids = n;
@@ -894,10 +890,8 @@ _public_ int sd_get_uids(uid_t **users) {
                         r++;
         }
 
-        if (users) {
-                *users = l;
-                l = NULL;
-        }
+        if (users)
+                *users = TAKE_PTR(l);
 
         return r;
 }
index 8e4e4efc81bae57c0e5a5630587e2d54cb4888c8..0b2824ee21f5d42c954c8fdd0d7b232ebfa0f6d7 100644 (file)
@@ -419,8 +419,7 @@ int seat_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
                 }
         }
 
-        *nodes = l;
-        l = NULL;
+        *nodes = TAKE_PTR(l);
 
         return 1;
 }
index b49b8b92ddb9b9ad3c7cc574b6024c6ba5dfb645..a0c3eda8f90d06a80c66a30ca4578e2578e0ccb3 100644 (file)
@@ -666,8 +666,7 @@ int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char
                 }
         }
 
-        *nodes = l;
-        l = NULL;
+        *nodes = TAKE_PTR(l);
 
         return 1;
 }
index d5d086cfe04c0b84af993ca3ef43b0c47751b768..ef1fce8bd1783dd05e47f371a7ba95c118e41d47 100644 (file)
@@ -354,8 +354,7 @@ int user_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
                 }
         }
 
-        *nodes = l;
-        l = NULL;
+        *nodes = TAKE_PTR(l);
 
         return 1;
 }
index 20b8601c1f6486a92deb338e7ecda09623152aa8..fd17b470e271b703c20356ec51f2361ce5676662 100644 (file)
@@ -100,8 +100,8 @@ int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name) {
         if (r < 0)
                 return r;
 
-        *out = u;
-        u = NULL;
+        *out = TAKE_PTR(u);
+
         return 0;
 }
 
index 1e000e101e2c6ab6f0b4c49f55f7b5b6f5a5e608..70f22bb9072a9732be96367b1cd7a55f87398074 100644 (file)
@@ -218,10 +218,8 @@ int acl_search_groups(const char *path, char ***ret_groups) {
                 r = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry);
         }
 
-        if (ret_groups) {
-                *ret_groups = g;
-                g = NULL;
-        }
+        if (ret_groups)
+                *ret_groups = TAKE_PTR(g);
 
         return ret;
 }
@@ -288,9 +286,8 @@ int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want
                 }
         }
 
-        *acl_access = a_acl;
-        *acl_default = d_acl;
-        a_acl = d_acl = NULL;
+        *acl_access = TAKE_PTR(a_acl);
+        *acl_default = TAKE_PTR(d_acl);
 
         return 0;
 }
@@ -394,8 +391,8 @@ int acls_for_file(const char *path, acl_type_t type, acl_t new, acl_t *acl) {
         if (r < 0)
                 return -errno;
 
-        *acl = old;
-        old = NULL;
+        *acl = TAKE_PTR(old);
+
         return 0;
 }
 
index 870ffbb2649648b08daac423afc02aaa3e4ae75a..ff098b7031a2d448e1e6b88e807fd39b50f55108 100644 (file)
@@ -607,8 +607,7 @@ int bus_connect_system_systemd(sd_bus **_bus) {
         if (r < 0)
                 return r;
 
-        *_bus = bus;
-        bus = NULL;
+        *_bus = TAKE_PTR(bus);
 
         return 0;
 }
@@ -645,8 +644,7 @@ int bus_connect_user_systemd(sd_bus **_bus) {
         if (r < 0)
                 return r;
 
-        *_bus = bus;
-        bus = NULL;
+        *_bus = TAKE_PTR(bus);
 
         return 0;
 }
@@ -1346,8 +1344,7 @@ int bus_connect_transport(BusTransport transport, const char *host, bool user, s
         if (r < 0)
                 return r;
 
-        *ret = bus;
-        bus = NULL;
+        *ret = TAKE_PTR(bus);
 
         return 0;
 }
@@ -1736,8 +1733,7 @@ int bus_open_system_watch_bind(sd_bus **ret) {
         if (r < 0)
                 return r;
 
-        *ret = bus;
-        bus = NULL;
+        *ret = TAKE_PTR(bus);
 
         return 0;
 }
index c7b453e8d0aebf51a47c7d529685a634079eaa9e..eebc05b0e8aa4ed07ed77703f627c4c8522febcc 100644 (file)
@@ -1184,8 +1184,7 @@ int config_parse_join_controllers(
         }
 
         strv_free_free(*ret);
-        *ret = controllers;
-        controllers = NULL;
+        *ret = TAKE_PTR(controllers);
 
         return 0;
 }