From nobody Fri May 3 10:00:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15040233843411016.7466250155509; Tue, 29 Aug 2017 09:16:24 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 62475C058EB7; Tue, 29 Aug 2017 16:16:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 37EA677D6F; Tue, 29 Aug 2017 16:16:20 +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 494913FC72; Tue, 29 Aug 2017 16:16:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7TGGEXa004315 for ; Tue, 29 Aug 2017 12:16:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3AFBA62675; Tue, 29 Aug 2017 16:16:14 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBD1B6364A for ; Tue, 29 Aug 2017 16:16:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 62475C058EB7 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 29 Aug 2017 18:16:09 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] lxcStateInitialize: Don't leak driver's caps 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 29 Aug 2017 16:16:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Funny thing. So when initializing LXC driver's capabilities, firstly the virLXCDriverGetCapabilities() is called. This creates new capabilities, stores them under driver->caps, ref() them and return them. However, the return value is ignored. Secondly, the function is called yet again and since we have driver->caps set, they are ref()-ed again an returned. So in the end, driver's capabilities have refcount of three when in fact they should have refcount of one. Signed-off-by: Michal Privoznik --- src/lxc/lxc_driver.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 6eb88b0ba..784edad39 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1660,7 +1660,7 @@ static int lxcStateInitialize(bool privileged, if (!(lxc_driver->hostdevMgr =3D virHostdevManagerGetDefault())) goto cleanup; =20 - if ((virLXCDriverGetCapabilities(lxc_driver, true)) =3D=3D NULL) + if (!(caps =3D virLXCDriverGetCapabilities(lxc_driver, true))) goto cleanup; =20 if (!(lxc_driver->xmlopt =3D lxcDomainXMLConfInit())) @@ -1669,9 +1669,6 @@ static int lxcStateInitialize(bool privileged, if (!(lxc_driver->closeCallbacks =3D virCloseCallbacksNew())) goto cleanup; =20 - if (!(caps =3D virLXCDriverGetCapabilities(lxc_driver, false))) - goto cleanup; - if (virFileMakePath(cfg->stateDir) < 0) { virReportSystemError(errno, _("Failed to mkdir %s"), @@ -1700,6 +1697,7 @@ static int lxcStateInitialize(bool privileged, goto cleanup; =20 virNWFilterRegisterCallbackDriver(&lxcCallbackDriver); + virObjectUnref(caps); return 0; =20 cleanup: --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list