* [Tarantool-patches] [PATCH] sql: fix memleak during parsing @ 2020-09-23 14:26 Roman Khabibov 2020-09-24 13:12 ` Nikita Pettik ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Roman Khabibov @ 2020-09-23 14:26 UTC (permalink / raw) To: tarantool-patches; +Cc: v.shpilevoy Fix a memory leak generated by allocation of indexes array of parser ephemeral space. --- Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/sql-memleak P.S. It's really memleak, I checked with valgrind. src/box/sql/tokenize.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c index 5404a78e9..6cf92b4f7 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -447,6 +447,8 @@ parser_space_delete(struct sql *db, struct space *space) assert(space->def->opts.is_ephemeral); for (uint32_t i = 0; i < space->index_count; ++i) index_def_delete(space->index[i]->def); + if (space->index_count != 0) + free(space->index); } /** -- 2.24.3 (Apple Git-128) ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Tarantool-patches] [PATCH] sql: fix memleak during parsing 2020-09-23 14:26 [Tarantool-patches] [PATCH] sql: fix memleak during parsing Roman Khabibov @ 2020-09-24 13:12 ` Nikita Pettik 2020-09-24 13:45 ` Roman Khabibov 2020-09-24 21:30 ` Vladislav Shpilevoy 2020-09-25 6:28 ` Kirill Yukhin 2 siblings, 1 reply; 5+ messages in thread From: Nikita Pettik @ 2020-09-24 13:12 UTC (permalink / raw) To: Roman Khabibov; +Cc: tarantool-patches, v.shpilevoy On 23 Sep 17:26, Roman Khabibov wrote: > Fix a memory leak generated by allocation of indexes array of > parser ephemeral space. > --- I'd fix a bit commit message: Fix a memory leak during execution of CREATE TABLE statement: indexes to be created are stored in space->index array, which in turn is allocated using malloc, but is never freed. LGTM otherwise. > Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/sql-memleak > > P.S. It's really memleak, I checked with valgrind. > > src/box/sql/tokenize.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c > index 5404a78e9..6cf92b4f7 100644 > --- a/src/box/sql/tokenize.c > +++ b/src/box/sql/tokenize.c > @@ -447,6 +447,8 @@ parser_space_delete(struct sql *db, struct space *space) > assert(space->def->opts.is_ephemeral); > for (uint32_t i = 0; i < space->index_count; ++i) > index_def_delete(space->index[i]->def); > + if (space->index_count != 0) > + free(space->index); > } > > /** > -- > 2.24.3 (Apple Git-128) > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Tarantool-patches] [PATCH] sql: fix memleak during parsing 2020-09-24 13:12 ` Nikita Pettik @ 2020-09-24 13:45 ` Roman Khabibov 0 siblings, 0 replies; 5+ messages in thread From: Roman Khabibov @ 2020-09-24 13:45 UTC (permalink / raw) To: Nikita Pettik; +Cc: tarantool-patches, Vladislav Shpilevoy Hello, thanks for the review! > On Sep 24, 2020, at 16:12, Nikita Pettik <korablev@tarantool.org> wrote: > > On 23 Sep 17:26, Roman Khabibov wrote: >> Fix a memory leak generated by allocation of indexes array of >> parser ephemeral space. >> --- > > I'd fix a bit commit message: > > Fix a memory leak during execution of CREATE TABLE statement: > indexes to be created are stored in space->index array, which in > turn is allocated using malloc, but is never freed. > > LGTM otherwise. > >> Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/sql-memleak >> >> P.S. It's really memleak, I checked with valgrind. >> >> src/box/sql/tokenize.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c >> index 5404a78e9..6cf92b4f7 100644 >> --- a/src/box/sql/tokenize.c >> +++ b/src/box/sql/tokenize.c >> @@ -447,6 +447,8 @@ parser_space_delete(struct sql *db, struct space *space) >> assert(space->def->opts.is_ephemeral); >> for (uint32_t i = 0; i < space->index_count; ++i) >> index_def_delete(space->index[i]->def); >> + if (space->index_count != 0) >> + free(space->index); >> } >> >> /** >> -- >> 2.24.3 (Apple Git-128) >> Done. commit b7de62663cde2a2b9d2181a9628602a560b268e1 Author: Roman Khabibov <roman.habibov@tarantool.org> Date: Wed Sep 23 14:40:23 2020 +0300 sql: fix memleak during parsing Fix a memory leak during execution of CREATE TABLE statement: indexes to be created are stored in space->index array, which in turn is allocated using malloc, but is never freed. diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c index 5404a78e9..6cf92b4f7 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -447,6 +447,8 @@ parser_space_delete(struct sql *db, struct space *space) assert(space->def->opts.is_ephemeral); for (uint32_t i = 0; i < space->index_count; ++i) index_def_delete(space->index[i]->def); + if (space->index_count != 0) + free(space->index); } /** ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Tarantool-patches] [PATCH] sql: fix memleak during parsing 2020-09-23 14:26 [Tarantool-patches] [PATCH] sql: fix memleak during parsing Roman Khabibov 2020-09-24 13:12 ` Nikita Pettik @ 2020-09-24 21:30 ` Vladislav Shpilevoy 2020-09-25 6:28 ` Kirill Yukhin 2 siblings, 0 replies; 5+ messages in thread From: Vladislav Shpilevoy @ 2020-09-24 21:30 UTC (permalink / raw) To: Roman Khabibov, tarantool-patches Hi! Thanks for the patch! > diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c > index 5404a78e9..6cf92b4f7 100644 > --- a/src/box/sql/tokenize.c > +++ b/src/box/sql/tokenize.c > @@ -447,6 +447,8 @@ parser_space_delete(struct sql *db, struct space *space) > assert(space->def->opts.is_ephemeral); > for (uint32_t i = 0; i < space->index_count; ++i) > index_def_delete(space->index[i]->def); > + if (space->index_count != 0) > + free(space->index); Why do you check for index_count != 0? free() works fine on NULL, which is the case when index_count is 0. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Tarantool-patches] [PATCH] sql: fix memleak during parsing 2020-09-23 14:26 [Tarantool-patches] [PATCH] sql: fix memleak during parsing Roman Khabibov 2020-09-24 13:12 ` Nikita Pettik 2020-09-24 21:30 ` Vladislav Shpilevoy @ 2020-09-25 6:28 ` Kirill Yukhin 2 siblings, 0 replies; 5+ messages in thread From: Kirill Yukhin @ 2020-09-25 6:28 UTC (permalink / raw) To: Roman Khabibov; +Cc: tarantool-patches, v.shpilevoy Hello, On 23 сен 17:26, Roman Khabibov wrote: > Fix a memory leak generated by allocation of indexes array of > parser ephemeral space. > --- > > Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/sql-memleak > > P.S. It's really memleak, I checked with valgrind. > > src/box/sql/tokenize.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c > index 5404a78e9..6cf92b4f7 100644 > --- a/src/box/sql/tokenize.c > +++ b/src/box/sql/tokenize.c > @@ -447,6 +447,8 @@ parser_space_delete(struct sql *db, struct space *space) > assert(space->def->opts.is_ephemeral); > for (uint32_t i = 0; i < space->index_count; ++i) > index_def_delete(space->index[i]->def); > + if (space->index_count != 0) > + free(space->index); What if there're more than 1 index? -- Regards, Kirill Yukhin ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-09-25 6:28 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-09-23 14:26 [Tarantool-patches] [PATCH] sql: fix memleak during parsing Roman Khabibov 2020-09-24 13:12 ` Nikita Pettik 2020-09-24 13:45 ` Roman Khabibov 2020-09-24 21:30 ` Vladislav Shpilevoy 2020-09-25 6:28 ` Kirill Yukhin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox