From nobody Sat Apr 20 14:07:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1590087524; cv=none; d=zohomail.com; s=zohoarc; b=I7vbXdhj0VgQek9u6bJhafE8rBPurpOUiMBt0M97uD+IwEW9n50UaBFIY4qaY0Qwq+v0cpeYvG5stD84KUieAk2YTgS4IsHsX1bSYRdayecqizrVwQxHQTgEMg2JriyfDmzfN3E5pfMvkL8187/zMMooPeM4Rz6fZmH/F4OkeVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590087524; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=l+oop/ljOhTVv58q9syNT04fO10TpRC6nZQh2efrYpo=; b=FARDsYMsb2yvdOy6t790HOnoM3XAElZWn7zNxJzXcF4c8SDpmdG9sw41cNGGLzULVHwxYb15f0WTSrRuDUzyxzVuKKfxkvarjspkASPey5sgmS5pMt6wF6FHcUDvMrsJUeMI1Dyi3aSbR+uwjvBBKWuqpThes9JmKXla1Hf2OZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1590087524245228.9443050585911; Thu, 21 May 2020 11:58:44 -0700 (PDT) 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-453-sh280wxzNxeiKwp1ooEoZQ-1; Thu, 21 May 2020 14:58:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90C2C1005512; Thu, 21 May 2020 18:58:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 193AD6E9EA; Thu, 21 May 2020 18:58:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1942218095FF; Thu, 21 May 2020 18:58:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04LIwTAw021585 for ; Thu, 21 May 2020 14:58:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 81C9A7959A; Thu, 21 May 2020 18:58:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00D5370461 for ; Thu, 21 May 2020 18:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590087522; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=l+oop/ljOhTVv58q9syNT04fO10TpRC6nZQh2efrYpo=; b=I79ThA0gG/VH7TSLw80+cMx9EI64DCCBeJYEGMXOqcI/8xnBrYt9OBFpunZAiXnjXtCFkW kHmsQsJJuhLbKIGPuq+XhxLZrq1Tbz01y5BQxinWdHdbYmcjT355dYyK/RHu82e9PVbNvr WF7gCHZI7SYnDbjEPNmiqxehIdZO/PE= X-MC-Unique: sh280wxzNxeiKwp1ooEoZQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] testCompareXMLToArgvValidateSchema: Construct @vm from scratch Date: Thu, 21 May 2020 20:58:23 +0200 Message-Id: <1cf03c733ddae24aa5f423bbeb89b98ad9b5f6f6.1590087503.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Currently, the @vm is passed in as an argument and testCompareXMLToArgvCreateArgs() is called over it which means under the hood qemuProcessPrepareDomain() is called. But at the point where ValidateSchema() is called, the domain object is already 'prepared', i.e. all device aliases are assigned and so on. But our code is not prepared to 'prepare' a domain twice - it simply overwrites all the pointers leading to a memory leak. Fortunately, this is only the problem of this test. Resolve this by constructing the domain object from scratch. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- tests/qemuxml2argvtest.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 4f613e8f1a..3103cac884 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -482,16 +482,17 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, =20 static int testCompareXMLToArgvValidateSchema(virQEMUDriverPtr drv, - virDomainObjPtr vm, const char *migrateURI, struct testQemuInfo *info, unsigned int flags) { VIR_AUTOSTRINGLIST args =3D NULL; + g_autoptr(virDomainObj) vm =3D NULL; size_t nargs =3D 0; size_t i; g_autoptr(virHashTable) schema =3D NULL; g_autoptr(virCommand) cmd =3D NULL; + unsigned int parseFlags =3D info->parseFlags; =20 if (info->schemafile) schema =3D testQEMUSchemaLoad(info->schemafile); @@ -504,6 +505,15 @@ testCompareXMLToArgvValidateSchema(virQEMUDriverPtr dr= v, if (!schema) return 0; =20 + if (!(vm =3D virDomainObjNew(driver.xmlopt))) + return -1; + + parseFlags |=3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + if (!(vm->def =3D virDomainDefParseFile(info->infile, + driver.xmlopt, + NULL, parseFlags))) + return -1; + if (!(cmd =3D testCompareXMLToArgvCreateArgs(drv, vm, migrateURI, info= , flags, true))) return -1; @@ -651,7 +661,7 @@ testCompareXMLToArgv(const void *data) goto cleanup; } =20 - if (testCompareXMLToArgvValidateSchema(&driver, vm, migrateURI, info, = flags) < 0) + if (testCompareXMLToArgvValidateSchema(&driver, migrateURI, info, flag= s) < 0) goto cleanup; =20 if (!(actualargv =3D virCommandToString(cmd, false))) --=20 2.26.2