From patchwork Wed Oct 28 17:14:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 537499 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 67FFA140D7C for ; Thu, 29 Oct 2015 04:26:35 +1100 (AEDT) Received: from localhost ([::1]:39633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrUUa-0003Ih-Eh for incoming@patchwork.ozlabs.org; Wed, 28 Oct 2015 13:26:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrUJe-0001QS-K1 for qemu-devel@nongnu.org; Wed, 28 Oct 2015 13:15:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrUJZ-0008Iu-He for qemu-devel@nongnu.org; Wed, 28 Oct 2015 13:15:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55195) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrUJZ-0008Ik-CT for qemu-devel@nongnu.org; Wed, 28 Oct 2015 13:15:09 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id EF1A7C0B5903; Wed, 28 Oct 2015 17:15:08 +0000 (UTC) Received: from red.redhat.com (ovpn-113-189.phx2.redhat.com [10.3.113.189]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9SHEZgJ031905; Wed, 28 Oct 2015 13:15:07 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 28 Oct 2015 11:14:31 -0600 Message-Id: <1446052473-19170-16-git-send-email-eblake@redhat.com> In-Reply-To: <1446052473-19170-1-git-send-email-eblake@redhat.com> References: <1446052473-19170-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v8 15/17] qapi: Test failure in middle of array parse 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 Our generated list visitors have the same problem as has been mentioned elsewhere (see commit 2f52e20): they allocate data even on failure. An upcoming patch will correct things to provide saner guarantees, but first we need to expose the behavior in the testsuite to ensure we aren't introducing any memory usage bugs. Signed-off-by: Eric Blake --- v8: no change v7: no change v6: rebase onto earlier gen_err_check() and testsuite improvements --- scripts/qapi-visit.py | 4 ++++ tests/test-qmp-input-visitor.c | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 948016d..4152f40 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -138,6 +138,10 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error def gen_visit_list(name, element_type): + # FIXME: if *obj is NULL on entry, and the first visit_next_list() + # assigns to *obj, while a later one fails, we should clean up *obj + # rather than leaving it non-NULL. As currently written, the caller must + # call qapi_free_FOOList() to avoid a memory leak of the partial FOOList. return mcgen(''' void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp) diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c index 4553210..df0bceb 100644 --- a/tests/test-qmp-input-visitor.c +++ b/tests/test-qmp-input-visitor.c @@ -698,6 +698,7 @@ static void test_visitor_in_errors(TestInputVisitorData *data, { TestStruct *p = NULL; Visitor *v; + strList *q = NULL; v = visitor_input_test_init(data, "{ 'integer': false, 'boolean': 'foo', 'string': -42 }"); @@ -709,6 +710,15 @@ static void test_visitor_in_errors(TestInputVisitorData *data, g_free(p->string); g_free(p); + + v = visitor_input_test_init(data, "[ '1', '2', false, '3' ]"); + /* FIXME - a failed parse should not leave a partially-allocated + * array for us to clean up; this could cause callers to leak + * memory. */ + visit_type_strList(v, &q, NULL, &data->err); + assert(q); + assert(data->err); + qapi_free_strList(q); } int main(int argc, char **argv)