[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v6 02/25] json-lexer: make it safe to call destroy multiple t
From: |
Damien Hedde |
Subject: |
Re: [PATCH v6 02/25] json-lexer: make it safe to call destroy multiple times |
Date: |
Fri, 8 Nov 2019 17:04:19 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 |
On 11/8/19 4:01 PM, Marc-André Lureau wrote:
> 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;
> + }
> }
>
Reviewed-by: Damien Hedde <address@hidden>
--
Damien
- [PATCH v6 00/25] monitor: add asynchronous command type, Marc-André Lureau, 2019/11/08
- [PATCH v6 01/25] qmp: constify QmpCommand and list, Marc-André Lureau, 2019/11/08
- [PATCH v6 02/25] json-lexer: make it safe to call destroy multiple times, Marc-André Lureau, 2019/11/08
- Re: [PATCH v6 02/25] json-lexer: make it safe to call destroy multiple times,
Damien Hedde <=
- [PATCH v6 03/25] qmp: add QmpSession, Marc-André Lureau, 2019/11/08
- [PATCH v6 04/25] QmpSession: add a return callback, Marc-André Lureau, 2019/11/08
- [PATCH v6 05/25] QmpSession: add json parser and use it in qga, Marc-André Lureau, 2019/11/08
- [PATCH v6 06/25] monitor: use qmp session to parse json feed, Marc-André Lureau, 2019/11/08
- [PATCH v6 07/25] qga: simplify dispatch_return_cb, Marc-André Lureau, 2019/11/08
- [PATCH v6 08/25] QmpSession: introduce QmpReturn, Marc-André Lureau, 2019/11/08
- [PATCH v6 09/25] qmp: simplify qmp_return_error(), Marc-André Lureau, 2019/11/08
- [PATCH v6 10/25] QmpSession: keep a queue of pending commands, Marc-André Lureau, 2019/11/08
- [PATCH v6 11/25] QmpSession: return orderly, Marc-André Lureau, 2019/11/08
- [PATCH v6 12/25] qmp: introduce asynchronous command type, Marc-André Lureau, 2019/11/08