From nobody Sun May 5 06:54:09 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579183740; cv=none; d=zohomail.com; s=zohoarc; b=QsFEvRHTuQFbybNKC9W/OOnJ22uhp6iuv1cm2tJW8FkEAwIagu8hSTfEw5Mq5oWUXMb6zU5GuGt17UVE3X4rTPRc84oDjlTNyfeK9D9nPIFzmPu30OeU/50MN31W0rcToByztOJT1Xma8RMtOvl8C/FYdGkDOm+0bIssS/AgnPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579183740; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=IIl4vIhCzvphxvQp5CpPqa6PsTD+Yz81NsM/TKK9TSU=; b=NKhpHcDCa+stgOcwq3GgZOFfrZk6STe1cx90NiyL+G6Eeog9KXvP7OLj66hiOI0XiE0yKLod+lZsF82j+iwf7zEHA48VAQ1DxF4guNp/ARAU4rSBLgfHE/eCAHGqNW03onkXNMrcFLh7Xv2AnUgIef7dbP5UtQ1ltj+zBlovMIs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579183740035395.6107063511091; Thu, 16 Jan 2020 06:09:00 -0800 (PST) Received: from localhost ([::1]:42542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is5pS-0004SG-Jt for importer@patchew.org; Thu, 16 Jan 2020 09:08:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48705) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is5oe-0003tt-Fe for qemu-devel@nongnu.org; Thu, 16 Jan 2020 09:08:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1is5oZ-0002DP-Hp for qemu-devel@nongnu.org; Thu, 16 Jan 2020 09:08:08 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:33798 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1is5oZ-0002CO-Dn for qemu-devel@nongnu.org; Thu, 16 Jan 2020 09:08:03 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-94-7AYLYGzDMcq7nr-rJSy3xA-1; Thu, 16 Jan 2020 09:07:48 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F8B410CE78A; Thu, 16 Jan 2020 14:07:48 +0000 (UTC) Received: from thuth.com (ovpn-204-105.brq.redhat.com [10.40.204.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id F21569CA3; Thu, 16 Jan 2020 14:07:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579183682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IIl4vIhCzvphxvQp5CpPqa6PsTD+Yz81NsM/TKK9TSU=; b=XmuchbaXHwVisGC/jMKPzDCxxjrsdeUY01rQcqJQoHTtxUVthLeYQ0z+i8uRrhJ5FE1cHP T7/cQUX+vrF2bBoy74TeQC7cYLsNNycw7s9ZzJ+3MdK5uuKBfQ2DMs9sqvN+E5oSf/2uWL /aBnTs1zzvzk4sIgR4NIVh3G7QwG9Tc= From: Thomas Huth To: qemu-devel@nongnu.org Subject: [PATCH] tests/qtest/vhost-user-test: Fix memory leaks Date: Thu, 16 Jan 2020 15:07:36 +0100 Message-Id: <20200116140736.9498-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 7AYLYGzDMcq7nr-rJSy3xA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , "Michael S . Tsirkin" , Pan Nengyuan , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Do not allocate resources in case we return early, and make sure to free dest_cmdline at the end. Reported-by: Euler Robot Reported-by: Pan Nengyuan Signed-off-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Based on a similar patch by Pan Nengyuan: https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg02183.html ... but that was causing some very weird problems in the gitlab CI for unknown reasons. This version now works fine in the gitlab CI. =20 tests/qtest/vhost-user-test.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 2324b964ad..9ee0f1e4fd 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -707,9 +707,9 @@ static void test_read_guest_mem(void *obj, void *arg, Q= GuestAllocator *alloc) static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc) { TestServer *s =3D arg; - TestServer *dest =3D test_server_new("dest"); - GString *dest_cmdline =3D g_string_new(qos_get_current_command_line()); - char *uri =3D g_strdup_printf("%s%s", "unix:", dest->mig_path); + TestServer *dest; + GString *dest_cmdline; + char *uri; QTestState *to; GSource *source; QDict *rsp; @@ -720,6 +720,10 @@ static void test_migrate(void *obj, void *arg, QGuestA= llocator *alloc) return; } =20 + dest =3D test_server_new("dest"); + dest_cmdline =3D g_string_new(qos_get_current_command_line()); + uri =3D g_strdup_printf("%s%s", "unix:", dest->mig_path); + size =3D get_log_size(s); g_assert_cmpint(size, =3D=3D, (256 * 1024 * 1024) / (VHOST_LOG_PAGE * = 8)); =20 @@ -778,6 +782,7 @@ static void test_migrate(void *obj, void *arg, QGuestAl= locator *alloc) qtest_quit(to); test_server_free(dest); g_free(uri); + g_string_free(dest_cmdline, true); } =20 static void wait_for_rings_started(TestServer *s, size_t count) --=20 2.18.1