From patchwork Fri May 10 22:46:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 243081 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 8C40D2C00E0 for ; Sat, 11 May 2013 08:49:25 +1000 (EST) Received: from localhost ([::1]:44148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uaw7v-0004Cx-RM for incoming@patchwork.ozlabs.org; Fri, 10 May 2013 18:49:23 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uaw62-0001ZA-3p for qemu-devel@nongnu.org; Fri, 10 May 2013 18:47:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uaw61-0001Tk-Al for qemu-devel@nongnu.org; Fri, 10 May 2013 18:47:26 -0400 Received: from mail-ia0-x234.google.com ([2607:f8b0:4001:c02::234]:38937) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uaw61-0001Te-5f for qemu-devel@nongnu.org; Fri, 10 May 2013 18:47:25 -0400 Received: by mail-ia0-f180.google.com with SMTP id 21so5253490iay.39 for ; Fri, 10 May 2013 15:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=1ha2Q9mQCXxhSp597PYqwoJeKg+nra8kiVHGtgBBDIM=; b=JdtRFnDkkM1a1OwL1DR6gfawXdzqIk5XGJk31ZSMhmyUPQkDHau1b2VcMOiqkuQsXz i/4Sc5FneNsbdm0OlAoXAqwjtid14BBfST2OW/8DAp/TQGJQXQVvJ8u3tNrcBpdqbeR9 S4gUGk7gKk14PLDucKBWjqVWzF/HNoaMJ562W9ADnfoU7qEyPV/LOOSLpAfPbAUQhRuE wn1YXno9pGd6CrCsSIk/OtSjNmX9gG5RcagNkjAcQT7iwCyJdeNBMhKfB4UqHH1ITpja ZJTs4jKKPZWcvBs98fMy3Zoc5gg9EiGQ0vYbdUJlNuQa8fGBaP7Vo9qIPrp9KxaYmJwG N8uA== X-Received: by 10.50.25.36 with SMTP id z4mr3698790igf.33.1368226044622; Fri, 10 May 2013 15:47:24 -0700 (PDT) Received: from localhost (cpe-72-177-121-217.austin.res.rr.com. [72.177.121.217]) by mx.google.com with ESMTPSA id l14sm866458igf.9.2013.05.10.15.47.23 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 10 May 2013 15:47:24 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Fri, 10 May 2013 17:46:04 -0500 Message-Id: <1368225970-28506-6-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1368225970-28506-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1368225970-28506-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c02::234 Cc: akong@redhat.com, lersek@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 05/11] qapi: fix leak in unit tests 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 qmp_output_get_qobject() increments the qobject's reference count. Since we currently pass this straight into qobject_to_json() so we can feed the data into a QMP input visitor, we never actually free the underlying qobject when qmp_output_visitor_cleanup() is called. This causes leaks on all of the QMP serialization tests. Fix this by holding a pointer to the qobject and decref'ing it before returning from qmp_deserialize(). Signed-off-by: Michael Roth --- tests/test-visitor-serialization.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c index e84926f..8c8adac 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -657,11 +657,16 @@ static void qmp_deserialize(void **native_out, void *datap, VisitorFunc visit, Error **errp) { QmpSerializeData *d = datap; - QString *output_json = qobject_to_json(qmp_output_get_qobject(d->qov)); - QObject *obj = qobject_from_json(qstring_get_str(output_json)); + QString *output_json; + QObject *obj_orig, *obj; + + obj_orig = qmp_output_get_qobject(d->qov); + output_json = qobject_to_json(obj_orig); + obj = qobject_from_json(qstring_get_str(output_json)); QDECREF(output_json); d->qiv = qmp_input_visitor_new(obj); + qobject_decref(obj_orig); qobject_decref(obj); visit(qmp_input_get_visitor(d->qiv), native_out, errp); }