Skip to content

Commit

Permalink
box: fix memory leaks on ER_MULTISTATEMENT_TRANSACTION in DDL
Browse files Browse the repository at this point in the history
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=<leak happens in small, cannot be detected by sanitizer>

(cherry picked from commit 6689f51)
  • Loading branch information
CuriousGeorgiy authored and locker committed Jun 23, 2023
1 parent 0802c68 commit 48d67e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions 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).
12 changes: 6 additions & 6 deletions src/box/memtx_space.c
Expand Up @@ -974,11 +974,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;
Expand Down Expand Up @@ -1224,6 +1224,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)
Expand All @@ -1237,9 +1240,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;
Expand Down

0 comments on commit 48d67e5

Please sign in to comment.