]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-varlink: use free_and_replace at one more place
authorMike Yuan <me@yhndnzj.com>
Wed, 11 Feb 2026 15:29:37 +0000 (16:29 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 16 Feb 2026 08:44:56 +0000 (09:44 +0100)
src/libsystemd/sd-varlink/sd-varlink.c

index 198713d440c4d76c367e47263c5f19d04e7a803a..d6d3b5bcb94233678a478e81073bd5ed9d6fc5b5 100644 (file)
@@ -1381,15 +1381,14 @@ static int varlink_format_queue(sd_varlink *v) {
          * would not corrupt our fd message boundaries */
 
         while (v->output_queue) {
-                _cleanup_free_ int *array = NULL;
-
                 assert(v->n_output_queue > 0);
 
-                VarlinkJsonQueueItem *q = v->output_queue;
-
                 if (v->n_output_fds > 0) /* unwritten fds? if we'd add more we'd corrupt the fd message boundaries, hence wait */
                         return 0;
 
+                VarlinkJsonQueueItem *q = v->output_queue;
+                _cleanup_free_ int *array = NULL;
+
                 if (q->n_fds > 0) {
                         array = newdup(int, q->fds, q->n_fds);
                         if (!array)
@@ -1401,8 +1400,7 @@ static int varlink_format_queue(sd_varlink *v) {
                         return r;
 
                 /* Take possession of the queue element's fds */
-                free(v->output_fds);
-                v->output_fds = TAKE_PTR(array);
+                free_and_replace(v->output_fds, array);
                 v->n_output_fds = q->n_fds;
                 q->n_fds = 0;