From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Luiz Capitulino 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> Subject: [Qemu-devel] [PATCH 07/13] qapi: allow freeing partially-allocated objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aliguori@us.ibm.com Cc: Paolo Bonzini , qemu-devel@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); -- 1.7.9.2.384.g4a92a