From patchwork Tue Mar 27 12:20:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 148935 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3EDD8B6EE7 for ; Tue, 27 Mar 2012 23:38:31 +1100 (EST) Received: from localhost ([::1]:36262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCVPM-00039G-Uo for incoming@patchwork.ozlabs.org; Tue, 27 Mar 2012 08:21:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCVOe-0001LU-3c for qemu-devel@nongnu.org; Tue, 27 Mar 2012 08:21:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCVOU-0000KQ-5e for qemu-devel@nongnu.org; Tue, 27 Mar 2012 08:21:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3859) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCVOT-0000KE-Tv for qemu-devel@nongnu.org; Tue, 27 Mar 2012 08:20:58 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2RCKuSZ032604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 27 Mar 2012 08:20:56 -0400 Received: from localhost (ovpn-113-71.phx2.redhat.com [10.3.113.71]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2RCKtkV006065; Tue, 27 Mar 2012 08:20:56 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Tue, 27 Mar 2012 09:20:45 -0300 Message-Id: <1332850851-4059-8-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1332850851-4059-1-git-send-email-lcapitulino@redhat.com> References: <1332850851-4059-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 07/13] qapi: allow freeing partially-allocated objects 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini Objects going through the dealloc visitor can be only partially allocated. Detect the situation and avoid a segfault. This also helps with the input visitor, when there are errors. Signed-off-by: Paolo Bonzini Reviewed-by: Anthony Liguori Signed-off-by: Luiz Capitulino --- scripts/qapi-visit.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 4297621..31d50a6 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -65,6 +65,9 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error ** return; } visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), errp); + if (obj && !*obj) { + goto end; + } ''', name=name) push_indent() @@ -72,6 +75,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error ** pop_indent() ret += mcgen(''' +end: visit_end_struct(m, errp); } ''') @@ -122,6 +126,9 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error ** return; } visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err); + if (obj && !*obj) { + goto end; + } visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err); if (err) { error_propagate(errp, err);