[tarantool-patches] Re: [PATCH v3 05/10] sql: refactor sql_expr_compile to return AST

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Thu Jun 14 22:27:14 MSK 2018


Thanks for the fixes! See 2 comments below.

Besides, I have pushed other review fixes as a separate commit. Please,
look and squash.

On 14/06/2018 20:32, Kirill Shcherbatov wrote:
> ---
>   src/box/alter.cc       |  6 +++---
>   src/box/sql.c          |  5 +++--
>   src/box/sql.h          |  9 ++++-----
>   src/box/sql/tokenize.c | 32 +++++++++++++++++++-------------
>   4 files changed, 29 insertions(+), 23 deletions(-)
> 
> diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c
> index 42c70a2..d84a840 100644
> --- a/src/box/sql/tokenize.c
> +++ b/src/box/sql/tokenize.c
> @@ -550,19 +555,20 @@ sql_expr_compile(sqlite3 *db, const char *expr, int expr_len,
>   	sql_parser_create(&parser, db);
>   	parser.parse_only = true;
>   
> +	struct Expr *expression = NULL;
>   	char *stmt = (char *)region_alloc(&parser.region, len + 1);
>   	if (stmt == NULL) {
>   		diag_set(OutOfMemory, len + 1, "region_alloc", "stmt");
> -		return -1;
> +		return NULL;

1. Here parser.region leaks.

>   	}
>   	sprintf(stmt, "%s%.*s", outer, expr_len, expr);
>   
> -	char *unused;
> -	if (sqlite3RunParser(&parser, stmt, &unused) != SQLITE_OK) {
> -		diag_set(ClientError, ER_SQL_EXECUTE, expr);
> -		return -1;
> -	}
> -	*result = parser.parsed_expr;
> +	char *sql_error;
> +	if (sqlite3RunParser(&parser, stmt, &sql_error) != SQLITE_OK &&
> +		parser.rc != SQL_TARANTOOL_ERROR)
> +		diag_set(ClientError, ER_SQL, sql_error);
> +	else
> +		expression = parser.parsed_expr;

2. If a TARANTOOL_ERROR has occurred and parsed_expr had been set before it,
then you return not NULL, but should return NULL.

And you should destroy the expression. Looks like it was a leak before your
patch. Lets always delete all the parsed expressions in parser_destroy (here
only parsed_expr is). And in this function on success nullify this member
before destroy.

>   	sql_parser_destroy(&parser);
> -	return 0;
> +	return expression;
>   }
> 




More information about the Tarantool-patches mailing list