From nobody Tue Nov 26 08:30:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1708840497; cv=none; d=zohomail.com; s=zohoarc; b=I05hwnPIqVLybslCFOVuGF2Tu7tG1ml0loBioKnsFMoYOfoEGmd1GSdtzs9x58cw7B59QlDm6d9T8A1Fu3jBicyB7FPLy1UKbBAySXUbppqPsFoD8KBnc8mfrvGlR/jq48jdnq8ffNoflF7vR0a42fc/iNCF7EizzQNvGva6Beo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708840497; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Z0h/tZr/hCGr4S4UnF/XAb1u/9XUlLx2lJTHeHYzEvs=; b=Uqr9WBWQYTMZkqxmLTASEa7jVJdlwoNTBr9FdpmrgNmg1xj2/3xkXb2r9qvY+f/yJaER3Hwxzk4MbLGzcGyuDCKse7V7B4ReifE6OEOAmOZ1O3/qdvYCocl1+vov78yN77OHXjdMm3LVh+aWYuTEWXzJi69TUXoG2NWVUBWCwrY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708840497215423.20456332681385; Sat, 24 Feb 2024 21:54:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1re7So-0000Qw-PS; Sun, 25 Feb 2024 00:54:15 -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 1re7Sm-0000Qd-8I for qemu-devel@nongnu.org; Sun, 25 Feb 2024 00:54:13 -0500 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1re7Si-0000Xk-6T for qemu-devel@nongnu.org; Sun, 25 Feb 2024 00:54:11 -0500 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3c19dcb76ccso18148b6e.0 for ; Sat, 24 Feb 2024 21:54:06 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id i18-20020aa79092000000b006e48b41aba7sm1893947pfa.12.2024.02.24.21.54.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 24 Feb 2024 21:54:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708840445; x=1709445245; darn=nongnu.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=Z0h/tZr/hCGr4S4UnF/XAb1u/9XUlLx2lJTHeHYzEvs=; b=r0Mp8uIaKIvNqa1QFsy2xOPNYSBk8V9i5CVdDyHEIHKqUpjwUrtXfhz5sGIiVOJnS0 xopoWmUt0RCO+QU3N5rn2UU9gXeFyjioUpObeT3ophWC8eNXDbWulKonTeHC7q85ffmR 59shLr+smbfakRdcHX6/JKo9zbTIylQdPVLTuWKWOd/SvDlmV0318J+D1r6/TD5A3B+N rPrll5IkUMSBW3A5ntyd5i69mCwvkOXdiDLoAcDCEl3aykD+nNBODJcBG3hxFygXt6Jg VdpUSF3JYYc/9FCWEM39ufKL49aRrUXU/Q/3FCMS4AJRkLKfxOxgZVVPuMjoYD7trHgB FxwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708840445; x=1709445245; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z0h/tZr/hCGr4S4UnF/XAb1u/9XUlLx2lJTHeHYzEvs=; b=lxi26oQA5G5vP0dF2p7y6v9R0aWvwJwCfQCZRC3Sc/M/wVWpO4nBOsRbEyep2DtIZs g++9/75HojV7jzF0O15eRjKVnC5X1Wmw0yJvkpXKsISDSl/0i6eTb657QJTqBZAKgL72 CZ31RplGjhFkS/v4p7/tste/DX/8LUzy6LNpY2rQ3Of5WkFbAbco0AZTgoBuH9ZIun8d YhAdq+cWEpk48TsjaCX3tg578OA1oni4utHRUnH6Kzul6FGS2Dd2NvTDDxBRaS7pwF8e OD/Jealv7N2ZcmRz8d5OaSpiAi6KX3qxjxYghIbhoR3ffakFgvJTcA0Zy2W1ksYjLnBq VxeQ== X-Gm-Message-State: AOJu0Ywk49CyDu2RNtBZ9B0njNbmQTmDXsDeAAYwnNx6iC80EviuANJc 6wH3+EOX8jajGMzjPS1Y2tnWsnHhx6pI4F9uotzvU4l1g8eSDBDzTFfHHflszhY= X-Google-Smtp-Source: AGHT+IFA6fBnquAUKq3EfIAJLXHhVslAXjWIa5exNgZSxRqpf4PrUs0ZbOJLgLVVKskmt7eU5CjDIw== X-Received: by 2002:aca:1314:0:b0:3c0:34b4:ee0f with SMTP id e20-20020aca1314000000b003c034b4ee0fmr3967648oii.53.1708840445313; Sat, 24 Feb 2024 21:54:05 -0800 (PST) From: Akihiko Odaki Date: Sun, 25 Feb 2024 14:54:01 +0900 Subject: [PATCH] migration: Free argv MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240225-argv-v1-1-a11e772884d9@daynix.com> X-B4-Tracking: v=1; b=H4sIAPjV2mUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDI0NL3cSi9DJdU0MLAzPTVCODVAtzJaDSgqLUtMwKsDHRsbW1AMfCxsN WAAAA To: Peter Xu , Fabiano Rosas Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::22d; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1708840498503100001 exec_start_outgoing_migration() and exec_start_incoming_migration() leak argv because it uses g_steal_pointer() is used to pass argv qio_channel_command_new_spawn() while it does not free argv either. Removing g_steal_pointer() is not sufficient though because argv is typed g_auto(GStrv), which means the array of strings *and strings* will be freed. The strings are only borrowed from the caller of exec_start_outgoing_migration() and exec_start_incoming_migration() so freeing them result in double-free. Instead, type argv as g_autofree char **. This ensures only the array of strings will be freed and the strings won't be freed. Also, remove unnecessary casts according to the new type. Fixes: cbab4face57b ("migration: convert exec backend to accept MigrateAddr= ess.") Signed-off-by: Akihiko Odaki Reviewed-by: Peter Xu --- migration/exec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/migration/exec.c b/migration/exec.c index 47d2f3b8fb02..205675265ea1 100644 --- a/migration/exec.c +++ b/migration/exec.c @@ -73,15 +73,15 @@ void exec_start_outgoing_migration(MigrationState *s, s= trList *command, QIOChannel *ioc; =20 int length =3D str_list_length(command); - g_auto(GStrv) argv =3D (char **) g_new0(const char *, length + 1); + g_autofree char **argv =3D g_new0(char *, length + 1); =20 init_exec_array(command, argv, errp); - g_autofree char *new_command =3D g_strjoinv(" ", (char **)argv); + g_autofree char *new_command =3D g_strjoinv(" ", argv); =20 trace_migration_exec_outgoing(new_command); ioc =3D QIO_CHANNEL( qio_channel_command_new_spawn( - (const char * const *) g_steal_pointer(&argv), + (const char * const *) argv, O_RDWR, errp)); if (!ioc) { @@ -107,15 +107,15 @@ void exec_start_incoming_migration(strList *command, = Error **errp) QIOChannel *ioc; =20 int length =3D str_list_length(command); - g_auto(GStrv) argv =3D (char **) g_new0(const char *, length + 1); + g_autofree char **argv =3D g_new0(char *, length + 1); =20 init_exec_array(command, argv, errp); - g_autofree char *new_command =3D g_strjoinv(" ", (char **)argv); + g_autofree char *new_command =3D g_strjoinv(" ", argv); =20 trace_migration_exec_incoming(new_command); ioc =3D QIO_CHANNEL( qio_channel_command_new_spawn( - (const char * const *) g_steal_pointer(&argv), + (const char * const *) argv, O_RDWR, errp)); if (!ioc) { --- base-commit: 5005aed8a7e728d028efb40e243ecfc2b4f3df3a change-id: 20240219-argv-518065e20e87 Best regards, --=20 Akihiko Odaki