From patchwork Mon Feb 26 14:11:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 775871 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp349227wrt; Mon, 26 Feb 2024 06:13:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW8TAlhFWuxfkIhBrf2BR8t8UTNiwhHwdzGULiE0agbv+3VCmik9B8znakY7pvoi160qgkUoeIC92v8jbVk6U12 X-Google-Smtp-Source: AGHT+IEESMK6/fzeNIU2cXSM9LrYPXh3g8Bj8MAVEKvWiXugN5PLXv8lmjK+kVsp73xVNGCrWgPe X-Received: by 2002:a05:6358:9148:b0:179:24b4:41fb with SMTP id r8-20020a056358914800b0017924b441fbmr4207484rwr.3.1708956810243; Mon, 26 Feb 2024 06:13:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708956810; cv=none; d=google.com; s=arc-20160816; b=B74zo6kn4aTdjxeFSuppc2xyImugE57gGp5ZkcIWIXPZ8MdTKPnBRU5P1UXKqJLScX pvB9vXGCGC4ZR5VAx4RB3h8z99IT9hUFS0yIKgrvMdmTj2UBP5jMsl+RvujMxItVI3H+ mjhfUkpo14nM9kB//KtK907kouC++/T+bqAg98z/RPevptkIWsdyDI6O2Ojn7Jg5jcGW P4EYcEKDZkLXB/SgX3hI9VYoRFwfetb/y+119YBP8/F0TNVcK2qoJYs1l0jt3RHRkNhf meVrZNEPvCgtNukjHg0xiyGJpT65y72OMY/wZEf84ZuHFQd8wfKJtK9Br3G8KbGOI9v4 wR7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eYUzkIrd2Io/eKJ09aaUbtIZJEnxRyBXW0AQqqMbZXw=; fh=k1vPAXquUc2EydDaefzATpGx9DFb05ahSbXBAdTSjso=; b=XGl8Ts0QLAZGOQNafCJ7/GBBDYs/WZYGggq38mI8gJYzutMngOfClDQCmuRmNplMDO LRYyoiPu7Yygz8tGfOQZWfMCM20xCzz5+mEOAfxYxgOGj/TiyqAnZr5CZBGeJGx9lwMr HdKBdYkiJroMdYi307H3a6jgeQcttUM71rUnc6akLSQhgUiDOvyFkDEhlqxaRtZf7wSC kdBiSi1GJdH/g4br+HbRkxGs/SgLizwJpQDV7hrDncD9NuAXQvLxBvey+19mb4E6u3B0 S6tMaIMIhYGc/XmX3GyZxNfcJWQgs/FTYR3sPZWSbx9LQD9aVkp2p67ok/z5TQcSNp74 PRyg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=impZdyAD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z23-20020ae9c117000000b007873bfc2e16si5170853qki.623.2024.02.26.06.13.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 06:13:30 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=impZdyAD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rebht-0003FU-Dt; Mon, 26 Feb 2024 09:11:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rebho-0003ER-VT for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:47 -0500 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rebhn-00026p-CP for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:44 -0500 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a437a2a46b1so67995766b.2 for ; Mon, 26 Feb 2024 06:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708956702; x=1709561502; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eYUzkIrd2Io/eKJ09aaUbtIZJEnxRyBXW0AQqqMbZXw=; b=impZdyADCj9awrzTG6hDalX5GtWW6MJK/zbfMfW+hovc44OrHI+SnydVQT6bY59fZL CUwqtaHlv1Bj2NutnuJEtFaxarEelh9FLSjCDWPN/Mk6RChWtpHJjeI+VQPqVltB69UI vqUs9NtnxxpvLHZPooeLL4UQEcy3yqi6swYfoSa05Fy2/xWiFyYbEFANLYHg/ryz91Vj AfVUS9NfKNP475sDXmKVvN++nSTKAifLqlMSqOHkJ0xaPQabyCv59nvqbULfXpjWWPBR OQs7NAIEGk5PxELcqnvc/gUUg4H4qxh+C9Lt83spOpKMBrQ7b+ErOBY3QwHtWncp+rWn JiUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708956702; x=1709561502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eYUzkIrd2Io/eKJ09aaUbtIZJEnxRyBXW0AQqqMbZXw=; b=QGfKY4PvJGVL6txsxZqDoLfjk5aEJFLKjHWh9w1ktMpMXN49DueQN06I6mbslSpWMV jfVxh1tyOhxASN/aGsjvDLU220MDt2d9KFKZ8P6UX4xuVyYWM3hYRtGbKlnLlXS9/gLw RHQUy28kyvFRWYUrcEL806rzcpUk5jUAmCANfIFdwv1PtBSMAu0UjvdZJt5sVTHlTcUF eZHpGMotDVV2vkEBfPa6cTXIqkYa4B3dOJzJ969XoqzJuf4lOH5L9OwVk/8jxTifANBw K9TbtwHaIeGUXj7h+an6T9VDUTemiPfK1qFSo7sUVkHjX4WxcNlMFNxSrALz3+MljKVw N5/g== X-Forwarded-Encrypted: i=1; AJvYcCU8qekCCej40zS1RdTQENIFyTwpK2T4iWW/KrEMKj5UCXpGk+x6ZHZd93sv1HA7RGyjOHvaXcxVIxpuoXJAB13WDDSKqeE= X-Gm-Message-State: AOJu0Yx6yAd3X7oGN0Vse0irluXQdmND7bJV+oVmI0bJRCV85fNfSMsl X8uYycCCmiKgRZHuKS0nM563S/sxXly2sRjlzZUkjys+4E4sh4owaaHU7xjxnmY= X-Received: by 2002:a17:906:c30f:b0:a43:8f7e:4249 with SMTP id s15-20020a170906c30f00b00a438f7e4249mr201861ejz.72.1708956701849; Mon, 26 Feb 2024 06:11:41 -0800 (PST) Received: from m1x-phil.lan ([176.187.223.153]) by smtp.gmail.com with ESMTPSA id ty6-20020a170907c70600b00a4354b9893csm892192ejc.74.2024.02.26.06.11.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 Feb 2024 06:11:41 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Markus Armbruster , qemu-devel@nongnu.org, Steve Sistare Cc: "Dr. David Alan Gilbert" , Jason Wang , Michael Roth , Peter Xu , Fabiano Rosas Subject: [PATCH v6 5/5] migration: simplify exec migration functions Date: Mon, 26 Feb 2024 15:11:07 +0100 Message-ID: <20240226141108.73664-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240226141108.73664-1-philmd@linaro.org> References: <20240226141108.73664-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=philmd@linaro.org; helo=mail-ej1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Steve Sistare Simplify the exec migration code by using list utility functions. As a side effect, this also fixes a minor memory leak. On function return, "g_auto(GStrv) argv" frees argv and each element, which is wrong, because the function does not own the individual elements. To compensate, the code uses g_steal_pointer which NULLs argv and prevents the destructor from running, but argv is leaked. Fixes: cbab4face57b ("migration: convert exec backend ...") Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas Message-ID: <1708638470-114846-6-git-send-email-steven.sistare@oracle.com> --- migration/exec.c | 57 +++++++----------------------------------------- 1 file changed, 8 insertions(+), 49 deletions(-) diff --git a/migration/exec.c b/migration/exec.c index 47d2f3b8fb..15184096ac 100644 --- a/migration/exec.c +++ b/migration/exec.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/strList.h" #include "channel.h" #include "exec.h" #include "migration.h" @@ -39,51 +40,16 @@ const char *exec_get_cmd_path(void) } #endif -/* provides the length of strList */ -static int -str_list_length(strList *list) -{ - int len = 0; - strList *elem; - - for (elem = list; elem != NULL; elem = elem->next) { - len++; - } - - return len; -} - -static void -init_exec_array(strList *command, char **argv, Error **errp) -{ - int i = 0; - strList *lst; - - for (lst = command; lst; lst = lst->next) { - argv[i++] = lst->value; - } - - argv[i] = NULL; - return; -} - void exec_start_outgoing_migration(MigrationState *s, strList *command, Error **errp) { - QIOChannel *ioc; - - int length = str_list_length(command); - g_auto(GStrv) argv = (char **) g_new0(const char *, length + 1); - - init_exec_array(command, argv, errp); + QIOChannel *ioc = NULL; + g_auto(GStrv) argv = strv_from_strList(command); + const char * const *args = (const char * const *) argv; g_autofree char *new_command = g_strjoinv(" ", (char **)argv); trace_migration_exec_outgoing(new_command); - ioc = QIO_CHANNEL( - qio_channel_command_new_spawn( - (const char * const *) g_steal_pointer(&argv), - O_RDWR, - errp)); + ioc = QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp)); if (!ioc) { return; } @@ -105,19 +71,12 @@ static gboolean exec_accept_incoming_migration(QIOChannel *ioc, void exec_start_incoming_migration(strList *command, Error **errp) { QIOChannel *ioc; - - int length = str_list_length(command); - g_auto(GStrv) argv = (char **) g_new0(const char *, length + 1); - - init_exec_array(command, argv, errp); + g_auto(GStrv) argv = strv_from_strList(command); + const char * const *args = (const char * const *) argv; g_autofree char *new_command = g_strjoinv(" ", (char **)argv); trace_migration_exec_incoming(new_command); - ioc = QIO_CHANNEL( - qio_channel_command_new_spawn( - (const char * const *) g_steal_pointer(&argv), - O_RDWR, - errp)); + ioc = QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp)); if (!ioc) { return; }