From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWrjl-0003bc-EU for qemu-devel@nongnu.org; Mon, 08 Aug 2016 17:05:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWrjh-0005mf-30 for qemu-devel@nongnu.org; Mon, 08 Aug 2016 17:05:28 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:10227 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWrjg-0005mY-Sk for qemu-devel@nongnu.org; Mon, 08 Aug 2016 17:05:25 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u78Kxl4E040315 for ; Mon, 8 Aug 2016 17:05:24 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0b-001b2d01.pphosted.com with ESMTP id 24nc30fjf1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 08 Aug 2016 17:05:24 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 8 Aug 2016 15:05:23 -0600 From: Michael Roth Date: Mon, 8 Aug 2016 16:03:42 -0500 In-Reply-To: <1470690267-31454-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1470690267-31454-1-git-send-email-mdroth@linux.vnet.ibm.com> Message-Id: <1470690267-31454-12-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 11/56] json-streamer: Don't leak tokens on incomplete parse List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Eric Blake , Markus Armbruster From: Eric Blake Valgrind complained about a number of leaks in tests/check-qobject-json: ==12657== definitely lost: 17,247 bytes in 1,234 blocks All of which had the same root cause: on an incomplete parse, we were abandoning the token queue without cleaning up the allocated data within each queue element. Introduced in commit 95385fe, when we switched from QList (which recursively frees contents) to g_queue (which does not). We don't yet require glib 2.32 with its g_queue_free_full(), so open-code it instead. CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Message-Id: <1463608012-12760-1-git-send-email-eblake@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster (cherry picked from commit ba4dba54347d5062436a8553f527dbbed6dcf069) Signed-off-by: Michael Roth --- qobject/json-streamer.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c index 0251685..7164390 100644 --- a/qobject/json-streamer.c +++ b/qobject/json-streamer.c @@ -20,9 +20,15 @@ #define MAX_TOKEN_COUNT (2ULL << 20) #define MAX_NESTING (1ULL << 10) +static void json_message_free_token(void *token, void *opaque) +{ + g_free(token); +} + static void json_message_free_tokens(JSONMessageParser *parser) { if (parser->tokens) { + g_queue_foreach(parser->tokens, json_message_free_token, NULL); g_queue_free(parser->tokens); parser->tokens = NULL; } -- 1.9.1