From nobody Sun Nov 24 09:44:45 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724165400; cv=none; d=zohomail.com; s=zohoarc; b=QjmLsCgGlRlpw83bJlggCSE+xW07YKlpkoHoigwaVdV1WEZbDHC9JkJMe8Lk7wMCw6YHKkv51FOKdADeFvQxL83z8uZYZDhaFtCHvLDlN9yeTMLmRguK/BWU60rJnRKhg8WmOT+2OJYFuCDbOfBil8mx36n9EJqr3sNN7i8pzKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724165400; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S5Xnpwm/2BcL3d4m231YwlBL4X22xMDqaWfh+yoj+U0=; b=Lo1Sp9knaXe+2EQ6zNnYQgUg7xubvbQCaTdr3bXAkPxcX5iay/gxt6hz/vjOjZAez0vp2e40T18Fa2mnyG7y3B6Vdnm+Nu1ZwoLs+4tjkbT2cDsTPdKp+TpWErrp4FCmQCDLsKsKKRGlu7HAti8KxSqI6R0954Fgc+vZcsHyYgo= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724165400608924.3892103335818; Tue, 20 Aug 2024 07:50:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgQAi-0004sC-6Y; Tue, 20 Aug 2024 10:49:20 -0400 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 1sgQAg-0004qu-8z for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:18 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgQAe-0006Kt-JW for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:18 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-42809d6e719so47468635e9.3 for ; Tue, 20 Aug 2024 07:49:16 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a306sm13334672f8f.15.2024.08.20.07.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724165354; x=1724770154; 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=S5Xnpwm/2BcL3d4m231YwlBL4X22xMDqaWfh+yoj+U0=; b=slTLsnkTkCH0hIHiqg9xzNB2Oiq9Y4FmDW1LbZ7vnugW58LbnY0qOZBmKbgKUMFIb8 fE6JT1Vme48Ko67zcoIVoosvY0l0Zwr/5yMjGhXQO1wkXvz5Cr5cHsaebB71femvVHoE DA0zxdKpshgb7PpYWOrVBO0nyIs4Jdi0qVTpRcDpB1FCChlv3Zw6/fMXDPLCXrDDE1La cY1tX5yewjQel6K/44b2OPP7Mgh5T2WKRhRFDYJwgG9MEpCBpdpiepxe4jVEQ7mBYWTE vaKlj6Iu1Z0MUHDLGc9OrEhJ5N4kNKoif+6XufRaqPLjFYiExI8deGLlot+UeSQZLxxU tbDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165354; x=1724770154; 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=S5Xnpwm/2BcL3d4m231YwlBL4X22xMDqaWfh+yoj+U0=; b=nTBepKbQ1AxjXPXnhINkQhZTxpsXDDY5Ry6q9SG5182P7qGCmnGLQYG8H41HSnylXQ uZ4cC8xVHxBCt8L4CITbECTERmYK1462LGERJE44japueSP1NJqCb6cAgAydSIayHjNQ HbeGudYMJ3DT+SYLstPp2qgAm3akwtfTOliGN6M0ep2/x2s6KubjqIYQQUVraRw0mOAO fNQzDOPpfPjBz6F32sxZPUQiq77cZ1p15aN9YoEHvTo8ELxIbaoAjNOsAJ/f0Iw+gcez ukgigt3QBIN6/lw3SWfZgSlrUMPxdT7NKEoZVQv4l50Rhb0eMIK81r37J0i8Ctrs4X8P bJ8g== X-Gm-Message-State: AOJu0Yz85c4EVCUQAVKExSaq6HtcK+5C6EUjzBnU7bVixq2d6I3G2BUH AQJVQMQ868oBWENd+cWJ0qyBIQLRq8R3k7zG+a6NAlOcI+sCIyDEW7duOtACgBfNSJl41PHfPs5 Q X-Google-Smtp-Source: AGHT+IHkvYzRz0RzdI3KyfVGbO0HJTwceWyNwtenMvo+lUyHBppZj99TqUV0cFOZMxiHeaGUSvdIlw== X-Received: by 2002:a5d:608c:0:b0:371:7e1b:871b with SMTP id ffacd0b85a97d-371c5fd0571mr1356984f8f.29.1724165354491; Tue, 20 Aug 2024 07:49:14 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH for-9.2 1/9] tests/qtest/migration-test: Fix bootfile cleanup handling Date: Tue, 20 Aug 2024 15:49:04 +0100 Message-Id: <20240820144912.320744-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820144912.320744-1-peter.maydell@linaro.org> References: <20240820144912.320744-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724165402284116600 Content-Type: text/plain; charset="utf-8" If you invoke the migration-test binary in such a way that it doesn't run any tests, then we never call bootfile_create(), and at the end of main() bootfile_delete() will try to unlink(NULL), which is not valid. This can happen if for instance you tell the test binary to run a subset of tests that turns out to be empty, like this: (cd build/asan && QTEST_QEMU_BINARY=3D./qemu-system-x86_64 ./tests/qtest/m= igration-test --tap -k -p bang) # random seed: R02S6501b289ff8ced4231ba452c3a87bc6f # Skipping test: userfaultfd not available 1..0 ../../tests/qtest/migration-test.c:182:12: runtime error: null pointer pas= sed as argument 1, which is declared to never be null /usr/include/unistd.h:858:48: note: nonnull attribute specified here Conversely, because we call bootfile_create() once per test but only call bootfile_delete() at the end of the whole test run, we will leak the memory we used for bootpath when we overwrite it. Handle these by: * making bootfile_delete() handle not needing to do anything because bootfile_create() was never called * making bootfile_create() call bootfile_delete() first to tidy up any previous bootfile before it creates a fresh one Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas --- I spotted this because I was trying to run a single subtest and messed up the test name so it didn't match anything :-) The second part was noticed by LeakSanitizer. --- tests/qtest/migration-test.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 70b606b8886..5cf238a4f05 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -144,12 +144,23 @@ static char *bootpath; #include "tests/migration/ppc64/a-b-kernel.h" #include "tests/migration/s390x/a-b-bios.h" =20 +static void bootfile_delete(void) +{ + if (!bootpath) { + return; + } + unlink(bootpath); + g_free(bootpath); + bootpath =3D NULL; +} + static void bootfile_create(char *dir, bool suspend_me) { const char *arch =3D qtest_get_arch(); unsigned char *content; size_t len; =20 + bootfile_delete(); bootpath =3D g_strdup_printf("%s/bootsect", dir); if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { /* the assembled x86 boot sector should be exactly one sector larg= e */ @@ -177,13 +188,6 @@ static void bootfile_create(char *dir, bool suspend_me) fclose(bootfile); } =20 -static void bootfile_delete(void) -{ - unlink(bootpath); - g_free(bootpath); - bootpath =3D NULL; -} - /* * Wait for some output in the serial output file, * we get an 'A' followed by an endless string of 'B's --=20 2.34.1 From nobody Sun Nov 24 09:44:45 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724165492; cv=none; d=zohomail.com; s=zohoarc; b=m17xsHIBIIai8a515cA8sw1UWbaHFdtwkfkVYVzORSYhEEFPymI/jXH2YV8aPdJ9yhZ4HmELE81MChxwjHmmnfFEGolHC8AtY6jDzYEwcGpGzWoiWlHNdzq1BOda8ZEDSVQrZ5bhSBQmzN9WMuPsg40VEeqfyIVTcPUHcCToWvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724165492; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i63bqDS44eEn4ijbQfvAhZ8JfystuRSkXcF0FbTNIZI=; b=SEOstSeCQ7r8QuyvanjXQ0DrwVjNCbue60W92qjcfTlGO8ayp4ag2c/Mq1WoMmCKVjiOx9OJGpvkT9xSHAqBD86VFUSvSObWvwLeAVcBZ1havwosTZMFKyQTQRtL+dGIBQnQrhTcK5J62oh1BuH4cH8MHphtRs8TYsngB4d5imY= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724165492447642.8007131864806; Tue, 20 Aug 2024 07:51:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgQAm-0005AD-AN; Tue, 20 Aug 2024 10:49:24 -0400 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 1sgQAi-0004wU-QS for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:21 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgQAf-0006L4-LT for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:19 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42808071810so45306025e9.1 for ; Tue, 20 Aug 2024 07:49:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a306sm13334672f8f.15.2024.08.20.07.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724165355; x=1724770155; 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=i63bqDS44eEn4ijbQfvAhZ8JfystuRSkXcF0FbTNIZI=; b=XTY3PdeZq0fx1dR8IZwhhebK6GxrBiFeCzucKmt/6a6nedm3lAnnwTjUWOY8Ev1WQM tk4mY0oW6m+xQAeD8KU0ohDX0S/T13DtT0H3S7cQYqTNO7jQnYSBgB/ag0V6KVS+5Gql 3hJtH9T0K3SAhXwizfLElPKp72pSxwCdBA8sjB+h9Kj0Q9+LE+psoBWCrKkfQIR7+G++ HruDiyAR2s/1bHISfRgqZRlCldnUoqH4b6SaFy4QtnyW+S/hSbYg2buO77r3L0sq97kf JvqQfmi4s/zVVDR0Z0JOrN3fkGzayU2T5mZL/QUSlWLuHLmg7Ui+RZrPWyXiPNHoSYaY am2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165355; x=1724770155; 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=i63bqDS44eEn4ijbQfvAhZ8JfystuRSkXcF0FbTNIZI=; b=mFkejoehsEGDzGdcmJrfZhNID0DtYywCCMmofUmORaCLWFh9Qv6/vZMZrZ5wASIE9/ tk+wUHdSycORHsD0txSHPZJfnyrVYZ7DbPlOcfuekv9TZTHyHWiayKB1XO3weK4E7xMJ h826kYrZIdKAd93eOVE7UjcTHV6C8A7UCDEDIMQqhHzsOyvKZfnYOqwHjnrgHdpjUHUG N4CpsWySTDyIdkwnve2hms2TwRgD0sHwe5biK2qdePowDuHrbPO1UHw5Eh5PyN3tWyLB x7xPIOMlzReDFCnGh5QZQiiUxjlv405ciUErrqP3tg/cyy0XqaKBAAEZURl5uey0r8tJ fw0Q== X-Gm-Message-State: AOJu0YxTIVjKf+t981Z2AkEmz3VfTUqQLr9624tcZrgNyuTVdMBKAWD/ SD1XaFUOp7ybdLv7FRZEcFlylbknBm9jAfa1gvx37YIJBZfsQX7PpwK0fk7q+zncCmg8018BGxe / X-Google-Smtp-Source: AGHT+IFJ+ckHQ3+S9h9nSmLwb0iAz36+alydO17x4JsUJkFcGASkYrvrmp9827tz4G3cvAZ0dIgtjA== X-Received: by 2002:adf:fe0f:0:b0:371:6fb9:95a with SMTP id ffacd0b85a97d-371944534c0mr11032323f8f.34.1724165355021; Tue, 20 Aug 2024 07:49:15 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH for-9.2 2/9] tests/qtest/migration-test: Don't leak resp in multifd_mapped_ram_fdset_end() Date: Tue, 20 Aug 2024 15:49:05 +0100 Message-Id: <20240820144912.320744-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820144912.320744-1-peter.maydell@linaro.org> References: <20240820144912.320744-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724165494722116600 Content-Type: text/plain; charset="utf-8" In multifd_mapped_ram_fdset_end() we call qtest_qmp() but forgot to unref the response QDict we get back, which means it is leaked: Indirect leak of 4120 byte(s) in 1 object(s) allocated from: #0 0x55c0c095d318 in __interceptor_calloc (/mnt/nvmedisk/linaro/qemu-fr= om-laptop/qemu/build/asan/tests/qtest/migration-test+0x22f318) (BuildI d: 07f667506452d6c467dbc06fd95191966d3e91b4) #1 0x7f186f939c50 in g_malloc0 debian/build/deb/../../../glib/gmem.c:16= 1:13 #2 0x55c0c0ae9b01 in qdict_new qobject/qdict.c:30:13 #3 0x55c0c0afc16c in parse_object qobject/json-parser.c:317:12 #4 0x55c0c0afb90f in parse_value qobject/json-parser.c:545:16 #5 0x55c0c0afb579 in json_parser_parse qobject/json-parser.c:579:14 #6 0x55c0c0afa21d in json_message_process_token qobject/json-streamer.c= :92:12 #7 0x55c0c0bca2e5 in json_lexer_feed_char qobject/json-lexer.c:313:13 #8 0x55c0c0bc97ce in json_lexer_feed qobject/json-lexer.c:350:9 #9 0x55c0c0afabbc in json_message_parser_feed qobject/json-streamer.c:1= 21:5 #10 0x55c0c09cbd52 in qmp_fd_receive tests/qtest/libqmp.c:86:9 #11 0x55c0c09be69b in qtest_qmp_receive_dict tests/qtest/libqtest.c:760= :12 #12 0x55c0c09bca77 in qtest_qmp_receive tests/qtest/libqtest.c:741:27 #13 0x55c0c09bee9d in qtest_vqmp tests/qtest/libqtest.c:812:12 #14 0x55c0c09bd257 in qtest_qmp tests/qtest/libqtest.c:835:16 #15 0x55c0c0a87747 in multifd_mapped_ram_fdset_end tests/qtest/migratio= n-test.c:2393:12 #16 0x55c0c0a85eb3 in test_file_common tests/qtest/migration-test.c:197= 8:9 #17 0x55c0c0a746a3 in test_multifd_file_mapped_ram_fdset tests/qtest/mi= gration-test.c:2437:5 #18 0x55c0c0a93237 in migration_test_wrapper tests/qtest/migration-help= ers.c:458:5 #19 0x7f186f958aed in test_case_run debian/build/deb/../../../glib/gtes= tutils.c:2930:15 #20 0x7f186f958aed in g_test_run_suite_internal debian/build/deb/../../= ../glib/gtestutils.c:3018:16 #21 0x7f186f95880a in g_test_run_suite_internal debian/build/deb/../../= ../glib/gtestutils.c:3035:18 #22 0x7f186f95880a in g_test_run_suite_internal debian/build/deb/../../= ../glib/gtestutils.c:3035:18 #23 0x7f186f95880a in g_test_run_suite_internal debian/build/deb/../../= ../glib/gtestutils.c:3035:18 #24 0x7f186f95880a in g_test_run_suite_internal debian/build/deb/../../= ../glib/gtestutils.c:3035:18 #25 0x7f186f95880a in g_test_run_suite_internal debian/build/deb/../../= ../glib/gtestutils.c:3035:18 #26 0x7f186f958faa in g_test_run_suite debian/build/deb/../../../glib/g= testutils.c:3109:18 #27 0x7f186f959055 in g_test_run debian/build/deb/../../../glib/gtestut= ils.c:2231:7 #28 0x7f186f959055 in g_test_run debian/build/deb/../../../glib/gtestut= ils.c:2218:1 #29 0x55c0c0a6e427 in main tests/qtest/migration-test.c:4033:11 Unref the object after we've confirmed that it is what we expect. Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas --- tests/qtest/migration-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 5cf238a4f05..6aba527340b 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2395,6 +2395,7 @@ static void multifd_mapped_ram_fdset_end(QTestState *= from, QTestState *to, g_assert(qdict_haskey(resp, "return")); fdsets =3D qdict_get_qlist(resp, "return"); g_assert(fdsets && qlist_empty(fdsets)); + qobject_unref(resp); } =20 static void *multifd_mapped_ram_fdset_dio(QTestState *from, QTestState *to) --=20 2.34.1 From nobody Sun Nov 24 09:44:45 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724165508; cv=none; d=zohomail.com; s=zohoarc; b=a5dINhmXlYmm9Y1BhpVXvmu0vAxSH4XU9FS06XIQk/c314BphnIyr78QnF/1+RuLpemgTIt7s+bcQrRkFvMlqPPxb06kxcUxXeS3LYQqiv5uhLMrQr8gT80TkmHNt7ze4i4bLachcOtp+LvXq7qZ+cVkjS/5PwfOtD1c891D5EQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724165508; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=srQqSMLi7+DN7GKyrDGJ1XhNsgSSac4GLNRUFZMUAQM=; b=YqqczvJwu6P5TWYxsmeMsjZK4OXaIaXRj0ozdWuh2NIJMtIPKY03nHWrqeb0upCkjT0bqNOYhSX+HlraAlBM18yL4rw04vMZVIcBOGw/Kz4Zu685wU1W6YmO/s7BkCHb5wyzpHChYD1FuxsShL9m+IeRhTFkngrs6KiCMLZeS98= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724165508839462.5199644225154; Tue, 20 Aug 2024 07:51:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgQAm-000591-0R; Tue, 20 Aug 2024 10:49:24 -0400 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 1sgQAi-0004wS-Qc for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:21 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgQAf-0006Kz-LR for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:18 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42ab880b73eso6775305e9.0 for ; Tue, 20 Aug 2024 07:49:16 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a306sm13334672f8f.15.2024.08.20.07.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724165356; x=1724770156; 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=srQqSMLi7+DN7GKyrDGJ1XhNsgSSac4GLNRUFZMUAQM=; b=Y7OTo7QTpxh1kyI+RK15lqZXxKWNntgoK9DtQEMcN0K9/amnwAuWP8RHlC3QV8abZG Xr0plf/LQChE47Ck7w0eyHF0zdEw+P5B8NvYKJ0QkpOFw6VRTf4vKSkVReP+21MevXnU iEJ47uO9tuvCmQuPYYP29ow5zDTETjw3yGMrswl+6bzG2k+gjxv/nSOcSnmPI97IjhPP V2wZjB5Q6xNBtXxKILaAH9AZqUCCiEFrx64bZoPTS7kk9KoVPwXOMqtm7ebicb3USJqC fKY10JyArv3F/B3+VxNkVuPmzuzRo4K6cAMnG1eHci5iNGUpJ3YKQ7RP3cruSF/kpFip rSBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165356; x=1724770156; 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=srQqSMLi7+DN7GKyrDGJ1XhNsgSSac4GLNRUFZMUAQM=; b=YYoECZp0YLJ2GP9on1TP+md1irmRTRuuO9wqwixTcUODzDq1eJKWPdF3I3Sl6KCCOc ar8JrEPH9gRD8SNlZU4X9TXOh5Hu1VZW+TuZI0MRzGYrLXUZxVoiIxEcXQerHl2O4s1f N5zOSgUiLQ0Ep8UrVdrY3TjSkkya5ftQPrf++izJ0BbIXdqEc+6oXCxk+Xo6wp5fshdE cIwCjtXJ1wKqFaJ1lcW1jke1tDUU6NUvfPKJd6RD5Wh10XeoQTvR3DIQAqr/RhsWlWhX 5AKedfBqXCIN7GvyRbKveWc/tUu76xuQoivxt3E+GQG/P+acQHFqXZGRHLIOyjD9WS/6 nFIQ== X-Gm-Message-State: AOJu0YzgQN358btKwSLw1J5+7T/ZyX+8KDzOur089b3Zrtk6KTXktpXV Z+1UlDFASyMVVa4XmoQEsFlHH2QslEsqX3wMgcwzf+deVKv6jPnPqDPEE/WjF4Ihd4iK+q9ia7c 1 X-Google-Smtp-Source: AGHT+IHxrkoKV4CBR7iOA/nTIHUoTupMfjzEN9DTVKrhiCY5MAjLPcJvm67J0gi3pHzrO3nV+wBrMw== X-Received: by 2002:a5d:498b:0:b0:36d:341d:270 with SMTP id ffacd0b85a97d-371946a4b4emr10329066f8f.59.1724165355480; Tue, 20 Aug 2024 07:49:15 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH for-9.2 3/9] tests/qtest/migration-test: Fix leaks in calc_dirtyrate_ready() Date: Tue, 20 Aug 2024 15:49:06 +0100 Message-Id: <20240820144912.320744-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820144912.320744-1-peter.maydell@linaro.org> References: <20240820144912.320744-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724165510631116600 Content-Type: text/plain; charset="utf-8" In calc_dirtyrate_ready() we g_strdup() a string but then never free it: Direct leak of 19 byte(s) in 2 object(s) allocated from: #0 0x55ead613413e in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu= /build/asan/tests/qtest/migration-test+0x22f13e) (BuildId: e7cd5c37b2987a1a= f682b43ee5240b98bb316737) #1 0x7f7a13d39738 in g_malloc debian/build/deb/../../../glib/gmem.c:128= :13 #2 0x7f7a13d4e583 in g_strdup debian/build/deb/../../../glib/gstrfuncs.= c:361:17 #3 0x55ead6266f48 in calc_dirtyrate_ready tests/qtest/migration-test.c:= 3409:14 #4 0x55ead62669fe in wait_for_calc_dirtyrate_complete tests/qtest/migra= tion-test.c:3422:13 #5 0x55ead6253df7 in test_vcpu_dirty_limit tests/qtest/migration-test.c= :3562:9 #6 0x55ead626a407 in migration_test_wrapper tests/qtest/migration-helpe= rs.c:456:5 We also fail to unref the QMP rsp_return, so we leak that also. Rather than duplicating the string, use the in-place value from the qdict, and then unref the qdict. Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas --- tests/qtest/migration-test.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 6aba527340b..9811047eeb4 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -3398,15 +3398,18 @@ static QDict *query_vcpu_dirty_limit(QTestState *wh= o) static bool calc_dirtyrate_ready(QTestState *who) { QDict *rsp_return; - gchar *status; + const char *status; + bool ready; =20 rsp_return =3D query_dirty_rate(who); g_assert(rsp_return); =20 - status =3D g_strdup(qdict_get_str(rsp_return, "status")); + status =3D qdict_get_str(rsp_return, "status"); g_assert(status); + ready =3D g_strcmp0(status, "measuring"); + qobject_unref(rsp_return); =20 - return g_strcmp0(status, "measuring"); + return ready; } =20 static void wait_for_calc_dirtyrate_complete(QTestState *who, --=20 2.34.1 From nobody Sun Nov 24 09:44:45 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724165418; cv=none; d=zohomail.com; s=zohoarc; b=NyyrZIzzJB6pw1u3pgK6h/u8LkPnJJhCDtdsnBa0aJYNRe0Err4G6DdwDcz1UazxVxUmrglJFi6h9224MeSFrVO3C4FPiYbiux2Vp6LRKGB0MvbXP30ahujzdz7UFbY21ymt2/Xtw5HJ8POMe1101xaK0ewN4Dg2eVi72CNg2sc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724165418; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=m2tt9btfYolQ5/KH5Y6XBbi1169Zr1kBebqADkF/0Ng=; b=Z1GPb+bQIdvC/1H4pbrI0olr0L6JrkQ9uJbNf0vpIfz42tWe6ZccyYT0MDsGBkIpq2SDt0jvukonAg53VYZTDjRPYN8UC6jKeLx0wP7UIh+WPhioNfjl08NhP2r0stLazo9brwMsGlQFNRwHPbpaPMY+3IArwMA8YZmf8siyXQk= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724165418922127.67953013344993; Tue, 20 Aug 2024 07:50:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgQAk-00050p-0V; Tue, 20 Aug 2024 10:49:22 -0400 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 1sgQAh-0004sj-Sq for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:20 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgQAf-0006L2-Lf for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:19 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4281faefea9so44578665e9.2 for ; Tue, 20 Aug 2024 07:49:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a306sm13334672f8f.15.2024.08.20.07.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724165356; x=1724770156; 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=m2tt9btfYolQ5/KH5Y6XBbi1169Zr1kBebqADkF/0Ng=; b=Z+EAyFSn26EzE8nX4Ed2oH08aCtu8bL+kV+3vEDYU6LK0JQKO6hl8gq13zpd41gDBr Yzx234x7TNHuSVMxmEfOxpgUoNi9oWTRlcPTcT4Pm9I2Mh45APt62widZBTDk3v8a11+ u4XgkokUPqwzBA+se6/+BZztC0FDqAt87Qw1pnhU1jxb4bpLLWvOIuCleaRdmtohV1qa uy9RPT4lrYRArnfQL3+vWHqzp47Wr5tJW0NmavTYggcnJwLtdi4ZgPN8BWs0C1l5oz/S +iBxjrXgSGvobKp5/PZQbiHCSVOL5bNqcvR54KEtxbwGwi7rmZ0VemrDnw5fJHzKFqhV Whnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165356; x=1724770156; 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=m2tt9btfYolQ5/KH5Y6XBbi1169Zr1kBebqADkF/0Ng=; b=YGjWVaHsFsMglttvi6kviBuyRiDyRa437cX00Zls59arYM59g95MqgXy/Zvh9Pk4iR ALRWKSukKDKOoqn4h71cHYDMGEPodIc+fbcNltpsUdxEge4YYLtRFw2Re3qVgWrAvjt9 Hme2QrSavbuqLhca6Yt1/c1XJQSVLXrGgW3zSvl8alOqRD8rqrfttCy3yOFtjp3I96Tw 0/GSSAne2n5iPuVg6YcT4FjBgsswi0PIpMFoO2q6CasdyIbwiuDCWM1+GGMKDOimdNii J8kDBUsXCIPP2t9BzsOmwJKwmE6+hIgLYZlDwyZ2tK/Lm1ji3C//p1qIytU+32Kxh6Z7 bzLw== X-Gm-Message-State: AOJu0YwkApbfsruBsSSiA8M7vU5fPiYOCeoeJOFaWojFyEOZvx9OTUdT PQ69y9/p6Ma022sfzQrhF9cte/mLa2Q8moOeU6tvsqkG8yt/gfpp6Ad5pqMIKIEj5SFI70JEcfs p X-Google-Smtp-Source: AGHT+IH0mpRybfWorbfvqpJ9Cx0C5U32cJIm9odTT70UG3zFn/RRu2XFjl+FcMqA0c86jIqMflrg6w== X-Received: by 2002:adf:f9d1:0:b0:368:30a6:16d8 with SMTP id ffacd0b85a97d-371946ccb85mr7823477f8f.57.1724165355984; Tue, 20 Aug 2024 07:49:15 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH for-9.2 4/9] tests/qtest/migration-helpers: Fix migrate_get_socket_address() leak Date: Tue, 20 Aug 2024 15:49:07 +0100 Message-Id: <20240820144912.320744-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820144912.320744-1-peter.maydell@linaro.org> References: <20240820144912.320744-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724165420341116600 Content-Type: text/plain; charset="utf-8" In migrate_get_socket_address() we leak the SocketAddressList: (cd build/asan && \ ASAN_OPTIONS=3D"fast_unwind_on_malloc=3D0:strip_path_prefix=3D/mnt/nvmedi= sk/linaro/qemu-from-laptop/qemu/build/asan/../../" QTEST_QEMU_BINARY=3D./qemu-system-x86_64 \ ./tests/qtest/migration-test --tap -k -p /x86_64/migration/multifd/tcp/tl= s/psk/match ) [...] Direct leak of 16 byte(s) in 1 object(s) allocated from: #0 0x563d7f22f318 in __interceptor_calloc (/mnt/nvmedisk/linaro/qemu-fr= om-laptop/qemu/build/asan/tests/qtest/migration-test+0x22f318) (BuildId: 2a= d6282fb5d076c863ab87f41a345d46dc965ded) #1 0x7f9de3b39c50 in g_malloc0 debian/build/deb/../../../glib/gmem.c:16= 1:13 #2 0x563d7f3a119c in qobject_input_start_list qapi/qobject-input-visito= r.c:336:17 #3 0x563d7f390fbf in visit_start_list qapi/qapi-visit-core.c:80:10 #4 0x563d7f3882ef in visit_type_SocketAddressList /mnt/nvmedisk/linaro/= qemu-from-laptop/qemu/build/asan/qapi/qapi-visit-sockets.c:519:10 #5 0x563d7f3658c9 in migrate_get_socket_address tests/qtest/migration-h= elpers.c:97:5 #6 0x563d7f362e24 in migrate_get_connect_uri tests/qtest/migration-help= ers.c:111:13 #7 0x563d7f362bb2 in migrate_qmp tests/qtest/migration-helpers.c:222:23 #8 0x563d7f3533cd in test_precopy_common tests/qtest/migration-test.c:1= 817:5 #9 0x563d7f34dc1c in test_multifd_tcp_tls_psk_match tests/qtest/migrati= on-test.c:3185:5 #10 0x563d7f365337 in migration_test_wrapper tests/qtest/migration-help= ers.c:458:5 The code fishes out the SocketAddress from the list to return it, and the callers are freeing that, but nothing frees the list. Since this function is called in only two places, the simple fix is to make it return the SocketAddressList rather than just a SocketAddress, and then the callers can easily access the SocketAddress, and free the whole SocketAddressList when they're done. Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas --- tests/qtest/migration-helpers.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index 84f49db85e0..7cbb9831e76 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -82,11 +82,10 @@ static QDict *SocketAddress_to_qdict(SocketAddress *add= r) return dict; } =20 -static SocketAddress *migrate_get_socket_address(QTestState *who) +static SocketAddressList *migrate_get_socket_address(QTestState *who) { QDict *rsp; SocketAddressList *addrs; - SocketAddress *addr; Visitor *iv =3D NULL; QObject *object; =20 @@ -95,36 +94,35 @@ static SocketAddress *migrate_get_socket_address(QTestS= tate *who) =20 iv =3D qobject_input_visitor_new(object); visit_type_SocketAddressList(iv, NULL, &addrs, &error_abort); - addr =3D addrs->value; visit_free(iv); =20 qobject_unref(rsp); - return addr; + return addrs; } =20 static char * migrate_get_connect_uri(QTestState *who) { - SocketAddress *addrs; + SocketAddressList *addrs; char *connect_uri; =20 addrs =3D migrate_get_socket_address(who); - connect_uri =3D SocketAddress_to_str(addrs); + connect_uri =3D SocketAddress_to_str(addrs->value); =20 - qapi_free_SocketAddress(addrs); + qapi_free_SocketAddressList(addrs); return connect_uri; } =20 static QDict * migrate_get_connect_qdict(QTestState *who) { - SocketAddress *addrs; + SocketAddressList *addrs; QDict *connect_qdict; =20 addrs =3D migrate_get_socket_address(who); - connect_qdict =3D SocketAddress_to_qdict(addrs); + connect_qdict =3D SocketAddress_to_qdict(addrs->value); =20 - qapi_free_SocketAddress(addrs); + qapi_free_SocketAddressList(addrs); return connect_qdict; } =20 --=20 2.34.1 From nobody Sun Nov 24 09:44:45 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724165481; cv=none; d=zohomail.com; s=zohoarc; b=lStGZAxinhCY1iBQi4/7D1KFjvIgLxge13F/RiImyGXx9iAMfG3LjiuNyUrikXBSHpU3zlTFjBt2BxL+CMIS2sJxZzMXO7mWsEgOnxRsSzU3N0//X+BsFr7qoMUfRAoDSszFQBQ/ZmQJPDRILDIw18uiHploEqMN3CClmBymHEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724165481; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sHKOV9DrTuAZNRw2GxXIgrum/jUoQJEGc0lRLc3B+xc=; b=V4+eHvfk/D41c7D7wAvAYeO9CD+iXX8PSyYkwR/4JCNH6CvMiq/trWX8RITfiaV4EvsP3l2khWZhKknPKIipFsyFjPoY065nKIJGg3CyJ9Ii/CyFAzlosz52Qfwx75dtl8C3bfDgl4Bo49zRbGDvzj6s+jOad2ErnGF9PmRNRHI= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724165481694135.62840277575538; Tue, 20 Aug 2024 07:51:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgQBD-0006hs-Di; Tue, 20 Aug 2024 10:49:51 -0400 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 1sgQAx-0005rj-3W for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:39 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgQAh-0006L7-I6 for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:34 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4281faefea9so44578755e9.2 for ; Tue, 20 Aug 2024 07:49:18 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a306sm13334672f8f.15.2024.08.20.07.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724165356; x=1724770156; 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=sHKOV9DrTuAZNRw2GxXIgrum/jUoQJEGc0lRLc3B+xc=; b=fm3w8hF2hgmf4pLuC8Yy7dSSfSLfGCEXrNrodmfaVPyxU/USdEMuXMqsPn585plWpV YQWQJkh0PW3ei0wTVES2/rhreXeJe4iDQVD7sLFsxQGaJR8nZRGXKOEgTlBab4477ZRu bFSuIVFJtmlUXrcTylWS5QgrcL12Clr3EHdnXiJ8ku3QBS/OGiGC4CdbzXZI7/4owtG9 TxAzE5GXgN+oLdvZUxBaMrIyKlAT4TR5R35/2EfwbjrQp6tWFTYShlUZoBL1PSf4EBcu gw0pz9Y+h1H+W4DORDnCLMdDs6+5o0WR+31uZK+QYEqAlxoqKsdZYa8xJMCx3eAgM96D rhpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165356; x=1724770156; 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=sHKOV9DrTuAZNRw2GxXIgrum/jUoQJEGc0lRLc3B+xc=; b=ro05fV3ABa+6lfeGqiMgAlNCxK3WgaDrB8tFhaWo9YL7o/CQZleutMsahmpM5jHfFd HCTiV0Xq5WJuGwrGDJ50Nl3nf8zZT+rICTIXpd1L5r787RCtwWrjYW/016v0aX2gBtnX zLPJZDL6ildZwcpLlFy0DydE8kri1DKkcKzFRkxYE90bwK4UazFPwkosNcpM+CinwpdH NIeJ73uTdcO8tRYFAeYUkaGhUdk9sxG0YilWdgcvmLRz5Cu+/RMN8SjjokKaew0p8kON OKe1yAN+Yv4EFzJ2PMzxEJJh8WRlZEElmriB7hImmb2oK/DaSHKHGI67cAq7l46mh5yH 7iCA== X-Gm-Message-State: AOJu0YzyPTR9tnGG0JhH7wlo6sHlePunu58yeNr5+ri6M+u/vkEUPPzS ECBLub4wurc7MKZp3NbHaauMt3/RN0IEx3R9pDzAIN7P4P2Wzw9M4Vcwhb614m1xEC4NRgxa2jf 7 X-Google-Smtp-Source: AGHT+IFAKynH2/06CakJs8Nu9W5Yyh3CngNNQPZEoaZw8ZZvIAx7j9NO60QNYgkLpnzqt58mozTbpg== X-Received: by 2002:a5d:408a:0:b0:371:8e77:92f with SMTP id ffacd0b85a97d-371946dc42emr7630739f8f.61.1724165356481; Tue, 20 Aug 2024 07:49:16 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH for-9.2 5/9] tests/qtest/migration-test: Free QCRyptoTLSTestCertReq objects Date: Tue, 20 Aug 2024 15:49:08 +0100 Message-Id: <20240820144912.320744-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820144912.320744-1-peter.maydell@linaro.org> References: <20240820144912.320744-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2a00:1450:4864:20::336; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x336.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724165482631116600 Content-Type: text/plain; charset="utf-8" In the migration test we create several TLS certificates with the TLS_* macros from crypto-tls-x509-helpers.h. These macros create both a QCryptoTLSCertReq object which must be deinitialized and also an on-disk certificate file. The migration test currently removes the on-disk file in test_migrate_tls_x509_finish() but never deinitializes the QCryptoTLSCertReq, which means that memory allocated as part of it is leaked: Indirect leak of 2 byte(s) in 1 object(s) allocated from: #0 0x5558ba33712e in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu= /build/asan/tests/qtest/migration-test+0x22f12e) (BuildId: 4c8618f663e53853= 8cad19d35233124cea161491) #1 0x7f64afc131f4 (/lib/x86_64-linux-gnu/libtasn1.so.6+0x81f4) (BuildI= d: 2fde6ecb43c586fe4077118f771077aa1298e7ea) #2 0x7f64afc18d58 in asn1_write_value (/lib/x86_64-linux-gnu/libtasn1.s= o.6+0xdd58) (BuildId: 2fde6ecb43c586fe4077118f771077aa1298e7ea) #3 0x7f64af8fc678 in gnutls_x509_crt_set_version (/lib/x86_64-linux-gnu= /libgnutls.so.30+0xe7678) (BuildId: 97b8f99f392f1fd37b969a7164bcea884e23649= b) #4 0x5558ba470035 in test_tls_generate_cert tests/unit/crypto-tls-x509-= helpers.c:234:5 #5 0x5558ba464e4a in test_migrate_tls_x509_start_common tests/qtest/mig= ration-test.c:1058:5 #6 0x5558ba462c8a in test_migrate_tls_x509_start_default_host tests/qte= st/migration-test.c:1123:12 #7 0x5558ba45ab40 in test_precopy_common tests/qtest/migration-test.c:1= 786:21 #8 0x5558ba450015 in test_precopy_unix_tls_x509_default_host tests/qtes= t/migration-test.c:2077:5 #9 0x5558ba46d3c7 in migration_test_wrapper tests/qtest/migration-helpe= rs.c:456:5 (and similar reports). The only function currently provided to deinit a QCryptoTLSCertReq is test_tls_discard_cert(), which also removes the on-disk certificate file. For the migration tests we need to retain the on-disk files until we've finished running the test, so the simplest fix is to provide a new function test_tls_deinit_cert() which does only the cleanup of the QCryptoTLSCertReq, and call it in the right places. Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas --- tests/unit/crypto-tls-x509-helpers.h | 6 ++++++ tests/qtest/migration-test.c | 3 +++ tests/unit/crypto-tls-x509-helpers.c | 12 ++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/unit/crypto-tls-x509-helpers.h b/tests/unit/crypto-tls-x= 509-helpers.h index 562c1606535..2a0f7c04fd8 100644 --- a/tests/unit/crypto-tls-x509-helpers.h +++ b/tests/unit/crypto-tls-x509-helpers.h @@ -73,6 +73,12 @@ void test_tls_generate_cert(QCryptoTLSTestCertReq *req, void test_tls_write_cert_chain(const char *filename, gnutls_x509_crt_t *certs, size_t ncerts); +/* + * Deinitialize the QCryptoTLSTestCertReq, but don't delete the certificate + * file on disk. (The caller is then responsible for doing that themselves. + */ +void test_tls_deinit_cert(QCryptoTLSTestCertReq *req); +/* Deinit the QCryptoTLSTestCertReq, and delete the certificate file */ void test_tls_discard_cert(QCryptoTLSTestCertReq *req); =20 void test_tls_init(const char *keyfile); diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 9811047eeb4..a659609ccb0 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1062,12 +1062,15 @@ test_migrate_tls_x509_start_common(QTestState *from, QCRYPTO_TLS_TEST_CLIENT_HOSTILE_NAME : QCRYPTO_TLS_TEST_CLIENT_NAME, data->clientcert); + test_tls_deinit_cert(&servercertreq); } =20 TLS_CERT_REQ_SIMPLE_SERVER(clientcertreq, cacertreq, data->servercert, args->certhostname, args->certipaddr); + test_tls_deinit_cert(&clientcertreq); + test_tls_deinit_cert(&cacertreq); =20 qtest_qmp_assert_success(from, "{ 'execute': 'object-add'," diff --git a/tests/unit/crypto-tls-x509-helpers.c b/tests/unit/crypto-tls-x= 509-helpers.c index 3e74ec5b5d4..b316155d6a6 100644 --- a/tests/unit/crypto-tls-x509-helpers.c +++ b/tests/unit/crypto-tls-x509-helpers.c @@ -502,8 +502,7 @@ void test_tls_write_cert_chain(const char *filename, g_free(buffer); } =20 - -void test_tls_discard_cert(QCryptoTLSTestCertReq *req) +void test_tls_deinit_cert(QCryptoTLSTestCertReq *req) { if (!req->crt) { return; @@ -511,6 +510,15 @@ void test_tls_discard_cert(QCryptoTLSTestCertReq *req) =20 gnutls_x509_crt_deinit(req->crt); req->crt =3D NULL; +} + +void test_tls_discard_cert(QCryptoTLSTestCertReq *req) +{ + if (!req->crt) { + return; + } + + test_tls_deinit_cert(req); =20 if (getenv("QEMU_TEST_DEBUG_CERTS") =3D=3D NULL) { unlink(req->filename); --=20 2.34.1 From nobody Sun Nov 24 09:44:45 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724165499; cv=none; d=zohomail.com; s=zohoarc; b=XpKi74VRlucWgFLmKPShi212tVKKCKT2JNVoIx01kM3WHnj1y9M2ktCyHJso0eX2kHSW4grQey6Lf9WPBHUDYSNTU39ekp+6XS2WubLbdiFkNhWXp386M/LqtT0ElDq5V3wuwbUqH+bszfig/VQ4nmaZtO9ZV5smIM81MF/+GRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724165499; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O5i4Lh15VMGVUspG/5ti46lsCaIByKJK9Dj5Y6QJ2cU=; b=BsyKsCgkhKhD2tlpmDAcgh/fTctooUqz76oo9Wgx6nBe/6LHiIlzEOskLqDkG68iLpysj1iqTMm9mpIMcHNbu3kQLXgOm1q1cqiLts6ponBBEFhPf9lXbdNazfAXbPIuY44ntM+z+fDtH2eIWy2ubjmPM8gXhBA07/se6/+EcxQ= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724165499422350.8828449454222; Tue, 20 Aug 2024 07:51:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgQAn-0005CQ-Bv; Tue, 20 Aug 2024 10:49:25 -0400 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 1sgQAk-00051c-36 for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:22 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgQAh-0006LF-JD for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:21 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-42ab99fb45dso7511415e9.1 for ; Tue, 20 Aug 2024 07:49:18 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a306sm13334672f8f.15.2024.08.20.07.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724165357; x=1724770157; 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=O5i4Lh15VMGVUspG/5ti46lsCaIByKJK9Dj5Y6QJ2cU=; b=gJ/SqTD/QMST3egftsV1OdXgaU75BnsWXNupZqAAt/WzgIWeyYIf8siEhguy84bIGQ umdkgtBM0iBO1707OfECIK+0yVIMWS5mOvx4YFdcGiLCUfxOxr2voSqJKujPdSanGqxy /Zqst5B/TM5zK0avzxrTKHWif9I9UQvVMO46lFgL6O8FVKjhNIHYAZSkt56nLqdlOTFr xSVOPN+OfGHDbg/joQktnOXc9XLsKive1ihqD5e+lwlGwcR9DxIRW2D9pxtMQ8Fn8f4Z Eh45Kqpnq49kwGCU/xJy7pluAtGm8h+Rr4IraSqoSmYRCwVTqOTrXb46TQcTVtJgusg0 2Nsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165357; x=1724770157; 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=O5i4Lh15VMGVUspG/5ti46lsCaIByKJK9Dj5Y6QJ2cU=; b=aczExRZkrX1CZCaNj3eFox7hEOOE683MrY1sp4MYqHXAeV/cUCl1krUsoQpl3c1ZTI 3mQ2bD6pdDHaRPNLeRwQoEdRzHBiq3ek5QD3vn/i+4SyUwuNNHmerKONJb/yqHNOITos hDzGPfirtJYn612vRK09Oi5ZPdgvBpF16tA8L7afGt9A+NLqCvk//2GyyOhw4yDqhlnH lFCOjSPZ8AH32utS7nQL9YHrMOUh8TBT8OVXa7mI/YxwKY4RzQVE1qCI79s/nk8/OpS9 /uPcctLHSY5BAfeBz+GlPdP9KBXs0EaS6YSxPRwaJkKR/tTczFDz1DyjeQeLlvu4noDe Pqig== X-Gm-Message-State: AOJu0Ywb8H3uIPENUAZIUNRvFlC9lEXuuzgdi9v8tSsmkq8PfDVjZwS1 tfrp91gmeQ0v3E/OUJjvKgqXtCsCLHNey7PRag64GFvtH1LyMo3s4SKgCVJAz5U7rtHdwiwU3UG G X-Google-Smtp-Source: AGHT+IEFiGJzLbHmY3enIPgbXkb2E3zZx3pqW3wM0BgJ71z2cXb5dFWeEPoAq6hapB+x5/c8oRQZlQ== X-Received: by 2002:adf:e907:0:b0:371:8e24:1191 with SMTP id ffacd0b85a97d-371946a4455mr11251605f8f.53.1724165356986; Tue, 20 Aug 2024 07:49:16 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH for-9.2 6/9] tests/unit/crypto-tls-x509-helpers: deinit privkey in test_tls_cleanup Date: Tue, 20 Aug 2024 15:49:09 +0100 Message-Id: <20240820144912.320744-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820144912.320744-1-peter.maydell@linaro.org> References: <20240820144912.320744-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724165500647116600 Content-Type: text/plain; charset="utf-8" We create a gnutls_x509_privkey_t in test_tls_init(), but forget to deinit it in test_tls_cleanup(), resulting in leaks reported in hte migration test such as: Indirect leak of 8 byte(s) in 1 object(s) allocated from: #0 0x55fa6d11c12e in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu= /build/asan/tests/qtest/migration-test+0x22f12e) (BuildId: 852a267993587f55= 7f50e5715f352f43720077ba) #1 0x7f073982685d in __gmp_default_allocate (/lib/x86_64-linux-gnu/libg= mp.so.10+0xa85d) (BuildId: f110719303ddbea25a5e89ff730fec520eed67b0) #2 0x7f0739836193 in __gmpz_realloc (/lib/x86_64-linux-gnu/libgmp.so.10= +0x1a193) (BuildId: f110719303ddbea25a5e89ff730fec520eed67b0) #3 0x7f0739836594 in __gmpz_import (/lib/x86_64-linux-gnu/libgmp.so.10+= 0x1a594) (BuildId: f110719303ddbea25a5e89ff730fec520eed67b0) #4 0x7f07398a91ed in nettle_mpz_set_str_256_u (/lib/x86_64-linux-gnu/li= bhogweed.so.6+0xb1ed) (BuildId: 3cc4a3474de72db89e9dcc93bfb95fe377f48c37) #5 0x7f073a146a5a (/lib/x86_64-linux-gnu/libgnutls.so.30+0x131a5a) (Bu= ildId: 97b8f99f392f1fd37b969a7164bcea884e23649b) #6 0x7f073a07192c (/lib/x86_64-linux-gnu/libgnutls.so.30+0x5c92c) (Bui= ldId: 97b8f99f392f1fd37b969a7164bcea884e23649b) #7 0x7f073a078333 (/lib/x86_64-linux-gnu/libgnutls.so.30+0x63333) (Bui= ldId: 97b8f99f392f1fd37b969a7164bcea884e23649b) #8 0x7f073a0e8353 (/lib/x86_64-linux-gnu/libgnutls.so.30+0xd3353) (Bui= ldId: 97b8f99f392f1fd37b969a7164bcea884e23649b) #9 0x7f073a0ef0ac in gnutls_x509_privkey_import (/lib/x86_64-linux-gnu/= libgnutls.so.30+0xda0ac) (BuildId: 97b8f99f392f1fd37b969a7164bcea884e23649b) #10 0x55fa6d2547e3 in test_tls_load_key tests/unit/crypto-tls-x509-help= ers.c:99:11 #11 0x55fa6d25460c in test_tls_init tests/unit/crypto-tls-x509-helpers.= c:128:15 #12 0x55fa6d2495c4 in test_migrate_tls_x509_start_common tests/qtest/mi= gration-test.c:1044:5 #13 0x55fa6d24c23a in test_migrate_tls_x509_start_reject_anon_client te= sts/qtest/migration-test.c:1216:12 #14 0x55fa6d23fb40 in test_precopy_common tests/qtest/migration-test.c:= 1789:21 #15 0x55fa6d236b7c in test_precopy_tcp_tls_x509_reject_anon_client test= s/qtest/migration-test.c:2614:5 (Oddly, there is no reported leak in the x509 unit tests, even though those also use test_tls_init() and test_tls_cleanup().) Deinit the privkey in test_tls_cleanup(). Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas --- tests/unit/crypto-tls-x509-helpers.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/crypto-tls-x509-helpers.c b/tests/unit/crypto-tls-x= 509-helpers.c index b316155d6a6..2daecc416c6 100644 --- a/tests/unit/crypto-tls-x509-helpers.c +++ b/tests/unit/crypto-tls-x509-helpers.c @@ -135,6 +135,7 @@ void test_tls_init(const char *keyfile) void test_tls_cleanup(const char *keyfile) { asn1_delete_structure(&pkix_asn1); + gnutls_x509_privkey_deinit(privkey); unlink(keyfile); } =20 --=20 2.34.1 From nobody Sun Nov 24 09:44:45 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724165440; cv=none; d=zohomail.com; s=zohoarc; b=VjTU4wZKgD1SCAEejZX+ikXuVB+7gzCLneG52Dhw69dnUM2zd6Pk1hiI5wbMjkTKKJ4KpeqfGsB90sRC9WNQ7Gy20ltdLBZCMMAwR8m6EnB1kvdmXvH0ozH3MwZS1YRzTLKz3nB3PpeXLC+zV/FNZTK8IVlWmnA98OPeeUozoOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724165440; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CAsHK7noev/bPNR4RNcwASEP9niT1BKYeUYjWLvcQsM=; b=A0Bkb3pqjvYdbsT6D5eRWoyj8MEdthZ6mZ4+IP11JQ06gpOYmns/mdjDom620u3FGxZrGjbHqR/WCYazzxBccXJSAfyzaCu/owlM+R8TivFEiS3Eirvv4oJAlo6HFWzTxmg4XHqmHbRdX4kD9hJymx3efrggqYDYc4Ozr8wouNk= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724165440580120.58100254718329; Tue, 20 Aug 2024 07:50:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgQB9-0006KZ-I8; Tue, 20 Aug 2024 10:49:47 -0400 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 1sgQAv-0005je-1e for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:39 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgQAh-0006LW-IQ for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:32 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-367990aaef3so3494883f8f.0 for ; Tue, 20 Aug 2024 07:49:19 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a306sm13334672f8f.15.2024.08.20.07.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724165358; x=1724770158; 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=CAsHK7noev/bPNR4RNcwASEP9niT1BKYeUYjWLvcQsM=; b=XErvckPsnWK0oGlnAykzftnBZMoMKb53qyA35fcdKdWo/kKonbG+urq9dBYVn+UA9j XLSXND/6OnNcVLm6L3XrHE8bZPhopuZGlfKh8SwgnvNDc//AUTc5OMQqumypnJ1qEi5X A+G+Lvb6phRDsGPzJaqNxTghGsnsnaIERlIRedUub5q9z/njaupw64VO2x9bQimI66XF vh3v1xNey8WhLwvLpyO7CTSINI93LZ/02M/voZ9RFYv5qlbxbQxngfaIDxOIkmXlpVe3 uS6GeZTlH5Z3uSI+jtXh9ZK+2ZvmhSkB5jaWQiF16Z6uFKsSWNYCaOq2SCWN5Ebk3ltj qD2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165358; x=1724770158; 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=CAsHK7noev/bPNR4RNcwASEP9niT1BKYeUYjWLvcQsM=; b=GFFd4rXmJRknBfJsIvgl0iehD28WuKpMSKsEFGcLNwWF/pFwJgkYf5t1DZRywdUTls TNKF2BQepvdCvSC1KvmD55FdK/HKqPVozRPb4Yyn/YSGZ6OPkdWZ4yvRALSXHDy010lY vjAN8RYphZjJ8Q21oRXHa7+81YlEkL1KVIVoeB4gRNzaWW52uiqQWqX+rt6VI1G7duZb 9kToi3d4IWeivAseMn6YSwpwkCe1Z5FN6nh2psJpFZPN9EH8YqCE57aYbOevwRyeSSHo icxmNFnLyXK5f/qJhYsE/8u7zXqaKoWxBCbGyW/OCjWWdnQ0X1SYuUSUS31PgKtE9Lxz 4JAA== X-Gm-Message-State: AOJu0YwibiiLZ+dYnkMR3YxpO5cjS33CwLZj8vRxjq47qpyxey1Mcudv FDrZ5f97wxpxeP95NA8aZmJu0ZGX0inq/gmR1OklBi+DR7mtEtMFiL7HGh4BDKUEgzdZxYn2nIL M X-Google-Smtp-Source: AGHT+IE/5KkZylplrHDrwD7Qjrx9dt8R5kjq7PFwLQIF2+zzDrxVHH5xe4qAgRxWFps99fcnExhAiw== X-Received: by 2002:a05:6000:e4d:b0:371:93d2:ce49 with SMTP id ffacd0b85a97d-3719468e998mr9256549f8f.44.1724165357684; Tue, 20 Aug 2024 07:49:17 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH for-9.2 7/9] tests/qtest/migration-helpers: Don't dup argument to qdict_put_str() Date: Tue, 20 Aug 2024 15:49:10 +0100 Message-Id: <20240820144912.320744-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820144912.320744-1-peter.maydell@linaro.org> References: <20240820144912.320744-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2a00:1450:4864:20::435; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x435.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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 @linaro.org) X-ZM-MESSAGEID: 1724165442515116600 Content-Type: text/plain; charset="utf-8" In migrate_set_ports() we call qdict_put_str() with a value string which we g_strdup(). However qdict_put_str() takes a copy of the value string, it doesn't take ownership of it, so the g_strdup() only results in a leak: Direct leak of 6 byte(s) in 1 object(s) allocated from: #0 0x56298023713e in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu= /build/asan/tests/qtest/migration-test+0x22f13e) (BuildId: b2b9174a5a54707a= 7f76bca51cdc95d2aa08bac1) #1 0x7fba0ad39738 in g_malloc debian/build/deb/../../../glib/gmem.c:128= :13 #2 0x7fba0ad4e583 in g_strdup debian/build/deb/../../../glib/gstrfuncs.= c:361:17 #3 0x56298036b16e in migrate_set_ports tests/qtest/migration-helpers.c:= 145:49 #4 0x56298036ad1c in migrate_qmp tests/qtest/migration-helpers.c:228:9 #5 0x56298035b3dd in test_precopy_common tests/qtest/migration-test.c:1= 820:5 #6 0x5629803549dc in test_multifd_tcp_channels_none tests/qtest/migrati= on-test.c:3077:5 #7 0x56298036d427 in migration_test_wrapper tests/qtest/migration-helpe= rs.c:456:5 Drop the unnecessary g_strdup() call. Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas --- tests/qtest/migration-helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index 7cbb9831e76..a43d180c807 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -142,7 +142,7 @@ static void migrate_set_ports(QTestState *to, QList *ch= annel_list) qdict_haskey(addr, "port") && (strcmp(qdict_get_str(addrdict, "port"), "0") =3D=3D 0)) { addr_port =3D qdict_get_str(addr, "port"); - qdict_put_str(addrdict, "port", g_strdup(addr_port)); + qdict_put_str(addrdict, "port", addr_port); } } =20 --=20 2.34.1 From nobody Sun Nov 24 09:44:45 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724165482; cv=none; d=zohomail.com; s=zohoarc; b=oH7n2Eqg/NrHEpTKJ137kDmTzaTSSb7nLZPS8yU2KeeZBJfEI37apyBAyw6vg+S39uPezkS2bo+usI7ebMHVkRkwQGQ8jnbY7RjJqyx+o4ah7laV5Yn4chIitLNFZw2yYjtT7C0O4qTTugce5/CSRkKAS8Gh3TKTDAQbd7Dp54g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724165482; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pRUkeG+dSEsxsUWMQJ/bL4Qbn7uE72qA/+aTs8IItt4=; b=QPM1S9MqUcKLHdbTGvV/dTNXCxo+FhWIAGfTWsRrFtOPLnly6zJFHoJtJ2Wr/abDABEEhkwGFSoiERFuxBehB+8yH4ps4uxjeBFTcs//xUGKvvReygXQUV/tmYgvddqaz2ykDLcH7t5129iM5S+d3MUZ4JILSFcn4mexzVPp4Is= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724165482292132.01554595426376; Tue, 20 Aug 2024 07:51:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgQAs-0005UM-7I; Tue, 20 Aug 2024 10:49:30 -0400 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 1sgQAk-000553-VT for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:23 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgQAj-0006Lc-46 for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:22 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-371941bbfb0so2783703f8f.0 for ; Tue, 20 Aug 2024 07:49:19 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a306sm13334672f8f.15.2024.08.20.07.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:49:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724165358; x=1724770158; 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=pRUkeG+dSEsxsUWMQJ/bL4Qbn7uE72qA/+aTs8IItt4=; b=l4eOzk4fA5N9FXk87e5lLrOC6Xg/EkVbznrmQwXfy2v/Lxc3icgIwv7njzYyA8cRHg naqbHrxEwupOdNNSB8ZZpH4bcfZiT28Lj49FCSYP6WND0DDFbHs2IwS2kuJLeJRk3wXr T2oTcBLl9mOuntiFrOSs66kipIBs3k9KDOpFLotXvLRIgxUQEDNz20YTsZnMsbdwm/sV KKC9CjG0iJ/kqZgzbzEP8jyF3iv4QZLQiKg+p2Au++1BUNxLU969kfGuE6LqbhqaJLNI UCgSWJ4lP7xZGZwSXiS29gyZqZYk0rynU1CguFL0DIatZl22X7yDHItk1MDzV/ncFA36 lqBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165358; x=1724770158; 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=pRUkeG+dSEsxsUWMQJ/bL4Qbn7uE72qA/+aTs8IItt4=; b=b2JfPOYw0OqVN2sVmruiwMEGswr+N+H77L/e8gPygHIaaeER7YN+eqDkYpxEhALYhy 3EoxxtT2U6eHINMjQFwUXZwr6eH6qJ51sda3lCXHjmnyL1QvI+0mvdUyVJAadNfKa0zX sfcZxG6Jvls3IYhZotxDchkqqnWF6BdhOoQ/Ajjbba/pmZEaOP0R7JFBDtLkZ6v7ydLo DppsZxNIW5iBDmmdYkipfM9kfgCuxLpEPh9YpW+z+8OiPvr0Ld7b/9tmGSRNjFo/Khx+ o4THYaBeeud1ZvvGA0DZ+0LymrNTA9hAoZ3v8hsGOIA5VZk2RQTQNbiFOKz/xY3Vimky Ed4A== X-Gm-Message-State: AOJu0YxQJiYDBI/7GCuSppTmeQK5d6RJoRh3ztYpWfRuLNqhB2x7Z9CR xu3gBd6VDNvFFIHrziKDNMs20xiUo1UUi2pBjSMluwe18xi3AMgFboq1rL/SR5xuvdlPDH/reAq U X-Google-Smtp-Source: AGHT+IE4XMLxhzJTWOaaHFsxJVepWxxpgZR4vXNbBBzKiTwXY94axfydZ1y1ku+8TkOHbsRe+/9z1A== X-Received: by 2002:a5d:408f:0:b0:371:83a8:afee with SMTP id ffacd0b85a97d-3719443d30emr9731301f8f.27.1724165358266; Tue, 20 Aug 2024 07:49:18 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH for-9.2 8/9] tests/qtest/migration-test: Don't strdup in get_dirty_rate() Date: Tue, 20 Aug 2024 15:49:11 +0100 Message-Id: <20240820144912.320744-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820144912.320744-1-peter.maydell@linaro.org> References: <20240820144912.320744-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2a00:1450:4864:20::430; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x430.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724165482591116600 Content-Type: text/plain; charset="utf-8" We g_strdup() the "status" string we get out of the qdict in get_dirty_rate(), but we never free it. Since we only use this string while the dictionary is still valid, we don't need to strdup at all; drop the unnecessary call to avoid this leak: Direct leak of 18 byte(s) in 2 object(s) allocated from: #0 0x564b3e01913e in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu= /build/asan/tests/qtest/migration-test+0x22f13e) (BuildId: d6403a811332fcc8= 46f93c45e23abfd06d1e67c4) #1 0x7f2f278ff738 in g_malloc debian/build/deb/../../../glib/gmem.c:128= :13 #2 0x7f2f27914583 in g_strdup debian/build/deb/../../../glib/gstrfuncs.= c:361:17 #3 0x564b3e14bb5b in get_dirty_rate tests/qtest/migration-test.c:3447:14 #4 0x564b3e138e00 in test_vcpu_dirty_limit tests/qtest/migration-test.c= :3565:16 #5 0x564b3e14f417 in migration_test_wrapper tests/qtest/migration-helpe= rs.c:456:5 Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas --- tests/qtest/migration-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index a659609ccb0..04122120987 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -3435,7 +3435,7 @@ static void wait_for_calc_dirtyrate_complete(QTestSta= te *who, static int64_t get_dirty_rate(QTestState *who) { QDict *rsp_return; - gchar *status; + const char *status; QList *rates; const QListEntry *entry; QDict *rate; @@ -3444,7 +3444,7 @@ static int64_t get_dirty_rate(QTestState *who) rsp_return =3D query_dirty_rate(who); g_assert(rsp_return); =20 - status =3D g_strdup(qdict_get_str(rsp_return, "status")); + status =3D qdict_get_str(rsp_return, "status"); g_assert(status); g_assert_cmpstr(status, =3D=3D, "measured"); =20 --=20 2.34.1 From nobody Sun Nov 24 09:44:45 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724165419; cv=none; d=zohomail.com; s=zohoarc; b=h3NE216XIEnJOhvhrbjt7ZJjNlDvLF6WUVGAdw7VngidZhXNDee/yg1GlDzJNMvz4vwZ1QW7Mghc9tQhcr1+lNz8J1S8BtMFukBRQYjMXEfxrDhCD0VVHqlc79K11aipW4a76DlhrirLuCKOVj9Odr49lcNSJ3X/OWPkw6wDGrY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724165419; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cX04CHrSO6RPXxQ10TYYxqNDsV8QV6DrYzWSCmg9HZE=; b=Xsk1k7O+pAjuBsM6ujZdNKfDPZreih/n3HK3nrk3GIrnAh5vp8/WVATw2OW+fpXtggOJ5m3kdgU5eq2oj3nM1nigoLWjV1J5pxjDWbZz+zkVLTdd1IW4k0PsLXqjJhI+6aJ2zsABqK15unC1wYzrifX6rlKEGD3HbB/IXC2SoDc= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724165419607749.4567459834545; Tue, 20 Aug 2024 07:50:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgQAn-0005F8-Ha; Tue, 20 Aug 2024 10:49:26 -0400 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 1sgQAl-00056l-D7 for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:23 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgQAj-0006M1-8P for qemu-devel@nongnu.org; Tue, 20 Aug 2024 10:49:23 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42812945633so49501165e9.0 for ; Tue, 20 Aug 2024 07:49:20 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a306sm13334672f8f.15.2024.08.20.07.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:49:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724165360; x=1724770160; 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=cX04CHrSO6RPXxQ10TYYxqNDsV8QV6DrYzWSCmg9HZE=; b=FzJ7wVj2E7IMABY3xTBwuf/0mhtu/9WQR3kAvHQAqoAuc5C5/33yWnDZH7/4e96JhP 8R0FiCu3qfb23441dFbV72hQVjYuc8VZjY59eQkfKPEzmdS+q531tDUxmG2jUrMYxw34 /262iBVpE7CNgQvNfNpik8elsMKidFC/k/akMYYjCb+7xHYlxpxaQQH2/lq43UfLS1wh rIuDDx40INCdfVNb9d3SMcoFuZj9lQhIE/vpz6xV/50oJWM84/+H7RTuE3/qrsF4u2/W 8Ykw7AJayhYx3tjNY26kDLmZEqMmNYgxVlj2PL8BL61squOpjD6j50YG9Mg32DYrEtLI 5tuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165360; x=1724770160; 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=cX04CHrSO6RPXxQ10TYYxqNDsV8QV6DrYzWSCmg9HZE=; b=U+UJHY4iQGO3aP/6kWYpyE8Ol783xJ4h3FqvYyXieRiEl8t+edYHkxYenAQiAq7FPA EgBuvMIs1+ldDZk3pm08FvdqmFSxa7GdfoOs2J2uWXKBvA32Yi6zuj+RxQ3I7diDa0SZ +j641uxZxuOez95ewrkg4LeIPp2mhTKZHxgxMSObhoshwARPSZl4zRpRZBNCiiNXvnY0 Gfa37ANKJd87thVCinmZQknzVz5uUh4A/dRP2g3HpXtDn0haJwWexS/4/VrgdK0mOiVC 380JAoJCNOsdZuBYuGke6a3eiicpvG/zG+6mBm2kePh4R1qut0QYInb7hhZRVBrU86Sh Rc6g== X-Gm-Message-State: AOJu0YyKII19Gz/36l4iqRtoiCFQb3svpKohYyuy6UIOTkiFIwBUw65a esxWC5jdy5BmYXZAnAZxXHw4iIIJwFKdOwCfeptTjvbGySknUdczDfblC68jF3IbTbDJDM99LGi 8 X-Google-Smtp-Source: AGHT+IHnDWcnCJrEnwVDXUDlG9y1adhxClOcx1t4xLNuadOY1NmlcCtCLEVXevJl97xfA6K11JTCHA== X-Received: by 2002:adf:ab18:0:b0:371:8ec6:f2f0 with SMTP id ffacd0b85a97d-3719432dcc3mr8507017f8f.16.1724165359671; Tue, 20 Aug 2024 07:49:19 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH for-9.2 9/9] tests/qtest/migration-test: Don't leak QTestState in test_multifd_tcp_cancel() Date: Tue, 20 Aug 2024 15:49:12 +0100 Message-Id: <20240820144912.320744-10-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820144912.320744-1-peter.maydell@linaro.org> References: <20240820144912.320744-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2a00:1450:4864:20::329; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x329.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724165420344116600 Content-Type: text/plain; charset="utf-8" In test_multifd_tcp_cancel() we create three QEMU processes: 'from', 'to' and 'to2'. We clean up (via qtest_quit()) 'from' and 'to2' when we call test_migrate_end(), but never clean up 'to', which results in this leak: Direct leak of 336 byte(s) in 1 object(s) allocated from: #0 0x55e984fcd328 in __interceptor_calloc (/mnt/nvmedisk/linaro/qemu-fr= om-laptop/qemu/build/asan/tests/qtest/migration-test+0x22f328) (BuildId: 71= 0d409b68bb04427009e9ca6e1b63ff8af785d3) #1 0x7f0878b39c50 in g_malloc0 debian/build/deb/../../../glib/gmem.c:16= 1:13 #2 0x55e98503a172 in qtest_spawn_qemu tests/qtest/libqtest.c:397:21 #3 0x55e98502bc4a in qtest_init_internal tests/qtest/libqtest.c:471:9 #4 0x55e98502c5b7 in qtest_init_with_env tests/qtest/libqtest.c:533:21 #5 0x55e9850eef0f in test_migrate_start tests/qtest/migration-test.c:85= 7:11 #6 0x55e9850eb01d in test_multifd_tcp_cancel tests/qtest/migration-test= .c:3297:9 #7 0x55e985103407 in migration_test_wrapper tests/qtest/migration-helpe= rs.c:456:5 Call qtest_quit() on 'to' to clean it up once it has exited. Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas --- tests/qtest/migration-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 04122120987..169ef0209c7 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -3322,6 +3322,7 @@ static void test_multifd_tcp_cancel(void) /* Make sure QEMU process "to" exited */ qtest_set_expected_status(to, EXIT_FAILURE); qtest_wait_qemu(to); + qtest_quit(to); =20 args =3D (MigrateStart){ .only_target =3D true, --=20 2.34.1