[Tarantool-patches] [PATCH 10/11] sql: fix usage of not initialized index_stat

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Jun 5 02:43:07 MSK 2020


Query planner uses a temporary index definition object 'to
represent the primary key index'. Whatever real purpose of this
index_def is (query planner wasn't changed since SQLite merge,
and may be broken), its opts.stat field pointed at a partially
initialized index_stat structure. Which is supposed to be used by
the planner to make decisions such as search by which index would
be the optimal.

The patch initializes the statistics with 0.

Part of #4609
---
 src/box/sql/where.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 7ec43e184..e9e936856 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -2794,9 +2794,9 @@ tnt_error:
 		fake_index->iid = UINT32_MAX;
 		int size = sizeof(struct index_stat) + sizeof(log_est_t) * 2;
 
-		struct index_stat *stat = (struct index_stat *) malloc(size);
+		struct index_stat *stat = (struct index_stat *) calloc(1, size);
 		if (stat == NULL) {
-			diag_set(OutOfMemory, size, "malloc", "stat");
+			diag_set(OutOfMemory, size, "calloc", "stat");
 			goto tnt_error;
 		}
 		stat->tuple_log_est = (log_est_t *) ((char *) (stat + 1));
-- 
2.21.1 (Apple Git-122.3)



More information about the Tarantool-patches mailing list