Received: from eggs.gnu.org ([2001:4830:134:3::10]:58584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4Q7M-0008Hq-2I for qemu-devel@nongnu.org; Wed, 09 Nov 2016 05:28:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4Q7H-0005T5-3P for qemu-devel@nongnu.org; Wed, 09 Nov 2016 05:28:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57210) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c4Q7G-0005S4-MB for qemu-devel@nongnu.org; Wed, 09 Nov 2016 05:28:27 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4065C056793 for ; Wed, 9 Nov 2016 10:28:25 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 9 Nov 2016 14:28:18 +0400 Message-Id: <20161109102818.9566-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCHv2] cipher: fix leak on initialization error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: berrange@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= On error path, ctx may be leaked. Assign ctx earlier, and call qcrypto_cipher_free() on error. Spotted thanks to ASAN. Signed-off-by: Marc-Andr=C3=A9 Lureau --- crypto/cipher-nettle.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c index cd094cd..5798910 100644 --- a/crypto/cipher-nettle.c +++ b/crypto/cipher-nettle.c @@ -254,6 +254,7 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgori= thm alg, cipher->mode =3D mode; =20 ctx =3D g_new0(QCryptoCipherNettle, 1); + cipher->opaque =3D ctx; =20 switch (alg) { case QCRYPTO_CIPHER_ALG_DES_RFB: @@ -384,13 +385,11 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgo= rithm alg, } =20 ctx->iv =3D g_new0(uint8_t, ctx->blocksize); - cipher->opaque =3D ctx; =20 return cipher; =20 error: - g_free(cipher); - g_free(ctx); + qcrypto_cipher_free(cipher); return NULL; } =20 --=20 2.10.0