From patchwork Mon Jan 18 10:25:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8054161 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0D98BBEEE5 for ; Mon, 18 Jan 2016 10:26:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D4F8203E9 for ; Mon, 18 Jan 2016 10:26:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AD8F9203E6 for ; Mon, 18 Jan 2016 10:26:06 +0000 (UTC) Received: from localhost ([::1]:58676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aL70f-0006xE-5T for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Jan 2016 05:26:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aL70Y-0006x5-Sp for qemu-devel@nongnu.org; Mon, 18 Jan 2016 05:25:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aL70U-0002We-S1 for qemu-devel@nongnu.org; Mon, 18 Jan 2016 05:25:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60512) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aL70U-0002WY-N4 for qemu-devel@nongnu.org; Mon, 18 Jan 2016 05:25:54 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id EE0EE746 for ; Mon, 18 Jan 2016 10:25:53 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0IAPpi1015431; Mon, 18 Jan 2016 05:25:52 -0500 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Jan 2016 11:25:51 +0100 Message-Id: <1453112751-725-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] qemu-char: avoid leak in qemu_chr_open_pp_fd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP drv leaks if qemu_chr_alloc returns an error. Signed-off-by: Paolo Bonzini Reviewed-by: Daniel P. Berrange --- qemu-char.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 9e2217b..2633b8a 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -1778,18 +1778,19 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd, return NULL; } - drv = g_new0(ParallelCharDriver, 1); - drv->fd = fd; - drv->mode = IEEE1284_MODE_COMPAT; - chr = qemu_chr_alloc(backend, errp); if (!chr) { return NULL; } + + drv = g_new0(ParallelCharDriver, 1); + chr->opaque = drv; chr->chr_write = null_chr_write; chr->chr_ioctl = pp_ioctl; chr->chr_close = pp_close; - chr->opaque = drv; + + drv->fd = fd; + drv->mode = IEEE1284_MODE_COMPAT; return chr; }