Received: from eggs.gnu.org ([2001:4830:134:3::10]:33448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJyLI-0002yo-JB for qemu-devel@nongnu.org; Mon, 04 Jul 2016 03:30:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJyLE-0002je-Is for qemu-devel@nongnu.org; Mon, 04 Jul 2016 03:30:56 -0400 Message-ID: <577A11C7.9030003@cn.fujitsu.com> Date: Mon, 4 Jul 2016 15:35:35 +0800 From: Changlong Xie MIME-Version: 1.0 References: <1463608012-12760-1-git-send-email-eblake@redhat.com> In-Reply-To: <1463608012-12760-1-git-send-email-eblake@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] json-streamer: Don't leak tokens on incomplete parse List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu-devel@nongnu.org Cc: pbonzini@redhat.com, Luiz Capitulino , armbru@redhat.com, qemu-stable@nongnu.org On 05/19/2016 05:46 AM, Eric Blake wrote: > 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 > --- > 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; > } > It seems this commit make tests/qemu-iotests/071 failed on the last master branch.