From c219f1ee9b7230987ac16a58d990f5329792c3cd Mon Sep 17 00:00:00 2001 From: Georgiy Lebedev Date: Tue, 20 Jun 2023 18:13:55 +0300 Subject: [PATCH] box: fix memory leaks on `ER_MULTISTATEMENT_TRANSACTION` in DDL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Space index build and space format checking operations don't destroy space iterator on `txn_check_singlestatement` failure — fix this. Closes #8773 NO_DOC=bugfix NO_TEST= (cherry picked from commit 6689f5111b2ef80757aaece353446b1717b23361) --- changelogs/unreleased/gh-8733-ddl-memory-leaks.md | 4 ++++ src/box/memtx_space.c | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 changelogs/unreleased/gh-8733-ddl-memory-leaks.md diff --git a/changelogs/unreleased/gh-8733-ddl-memory-leaks.md b/changelogs/unreleased/gh-8733-ddl-memory-leaks.md new file mode 100644 index 000000000000..e95d36d690a8 --- /dev/null +++ b/changelogs/unreleased/gh-8733-ddl-memory-leaks.md @@ -0,0 +1,4 @@ +## bugfix/box + +* Fixed the memory leaks caused by the multi-statement transaction errors in the + space index building and the space format checking operations (gh-8773). diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c index 55f897220c54..a3771a71fe3b 100644 --- a/src/box/memtx_space.c +++ b/src/box/memtx_space.c @@ -984,11 +984,11 @@ memtx_space_check_format(struct space *space, struct tuple_format *format) if (index_size(pk) == 0) return 0; - struct iterator *it = index_create_iterator(pk, ITER_ALL, NULL, 0); - if (it == NULL) + if (txn_check_singlestatement(txn, "space format check") != 0) return -1; - if (txn_check_singlestatement(txn, "space format check") != 0) + struct iterator *it = index_create_iterator(pk, ITER_ALL, NULL, 0); + if (it == NULL) return -1; struct memtx_engine *memtx = (struct memtx_engine *)space->engine; @@ -1233,6 +1233,9 @@ memtx_space_build_index(struct space *src_space, struct index *new_index, return -1; } + if (txn_check_singlestatement(txn, "index build") != 0) + return -1; + /* Now deal with any kind of add index during normal operation. */ struct iterator *it = index_create_iterator(pk, ITER_ALL, NULL, 0); if (it == NULL) @@ -1246,9 +1249,6 @@ memtx_space_build_index(struct space *src_space, struct index *new_index, */ bool can_yield = pk->def->type != HASH; - if (txn_check_singlestatement(txn, "index build") != 0) - return -1; - struct memtx_engine *memtx = (struct memtx_engine *)src_space->engine; struct memtx_ddl_state state; struct trigger on_replace;