Skip to content

Commit

Permalink
json-streamer: fix double-free on exiting during a parse
Browse files Browse the repository at this point in the history
Now that json-streamer tries not to leak tokens on incomplete parse,
the tokens can be freed twice if QEMU destroys the json-streamer
object during the parser->emit call.  To fix this, create the new
empty GQueue earlier, so that it is already in place when the old
one is passed to parser->emit.

Reported-by: Changlong Xie <xiecl.fnst@cn.fujitsu.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1467636059-12557-1-git-send-email-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit a942d8f)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
bonzini authored and mdroth committed Aug 4, 2016
1 parent ebe0376 commit 2522f0f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions qobject/json-streamer.c
Expand Up @@ -39,6 +39,7 @@ static void json_message_process_token(JSONLexer *lexer, GString *input,
{
JSONMessageParser *parser = container_of(lexer, JSONMessageParser, lexer);
JSONToken *token;
GQueue *tokens;

switch (type) {
case JSON_LCURLY:
Expand Down Expand Up @@ -96,9 +97,12 @@ static void json_message_process_token(JSONLexer *lexer, GString *input,
/* send current list of tokens to parser and reset tokenizer */
parser->brace_count = 0;
parser->bracket_count = 0;
/* parser->emit takes ownership of parser->tokens. */
parser->emit(parser, parser->tokens);
/* parser->emit takes ownership of parser->tokens. Remove our own
* reference to parser->tokens before handing it out to parser->emit.
*/
tokens = parser->tokens;
parser->tokens = g_queue_new();
parser->emit(parser, tokens);
parser->token_size = 0;
}

Expand Down

0 comments on commit 2522f0f

Please sign in to comment.