[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 02/20] json-lexer: make it safe to call destroy m
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v4 02/20] json-lexer: make it safe to call destroy multiple times |
Date: |
Tue, 9 Apr 2019 18:09:51 +0200 |
We can easily avoid the burden of checking if the lexer was
initialized prior to calling destroy by the caller, let's do it.
This allows simplification in state tracking with the following patch,
"qmp: add QmpSession" can call qmp_session_destroy() multiple times,
which in turns calls json_lexer_destroy().
Signed-off-by: Marc-André Lureau <address@hidden>
---
qobject/json-lexer.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
index 632320d72d..fa7a2c43a8 100644
--- a/qobject/json-lexer.c
+++ b/qobject/json-lexer.c
@@ -361,5 +361,8 @@ void json_lexer_flush(JSONLexer *lexer)
void json_lexer_destroy(JSONLexer *lexer)
{
- g_string_free(lexer->token, true);
+ if (lexer->token) {
+ g_string_free(lexer->token, true);
+ lexer->token = NULL;
+ }
}
--
2.21.0.196.g041f5ea1cf
- [Qemu-devel] [PATCH v4 00/20] monitor: add asynchronous command type, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 01/20] qmp: constify QmpCommand and list, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 02/20] json-lexer: make it safe to call destroy multiple times,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v4 03/20] qmp: add QmpSession, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 04/20] QmpSession: add a return callback, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 05/20] QmpSession: add json parser and use it in qga, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 06/20] monitor: use qmp session to parse json feed, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 07/20] qga: simplify dispatch_return_cb, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 08/20] QmpSession: introduce QmpReturn, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 09/20] qmp: simplify qmp_return_error(), Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 11/20] QmpSession: return orderly, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 12/20] qmp: introduce asynchronous command type, Marc-André Lureau, 2019/04/09
- [Qemu-devel] [PATCH v4 13/20] scripts: learn 'async' qapi commands, Marc-André Lureau, 2019/04/09