Correctly deallocate string vectors#221
Conversation
|
Update here: string vectors were not deallocated correctly. By applying the current status of this PR, I could not reproduce the error described in #220 anymore. With the current master, I reproduced the error. |
|
So which files did you actually modify and which have been generated? |
I only touched the few lines (destructor for |
Bouncner
left a comment
There was a problem hiding this comment.
Can't judge this PR, but the (non automated) change make sense to me.
This merge brings 107 commits from upstream hyrise/sql-parser while preserving the MySQL-specific extensions from the Envoy fork: Upstream features included: - Window functions support (hyrise#233) - Row locking grammar (hyrise#205) - FOREIGN KEY constraints (hyrise#252) - NULLS FIRST/LAST in ORDER BY (hyrise#257) - BIGINT, SMALLINT, TIMESTAMP, BOOLEAN data types - Date/interval literals - Named columns for joins fix (hyrise#240) - String vector deallocation fix (hyrise#221) - GCC-13 compatibility (hyrise#245) - ARM Mac support (hyrise#216) - CSV import options for DELIMITER, NULL, QUOTE (hyrise#256) - Various bug fixes and improvements Fork features preserved: - tablesAccessed() method for tracking table access operations - MySQL-specific syntax: backticks, LOW_PRIORITY, IGNORE, QUICK - MySQL statements: CREATE/DROP/ALTER DATABASE, SHOW DATABASES - TEMPORARY tables, ALTER TABLE ADD COLUMN - include/sqlparser/ directory structure Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Jonh Wendell <jwendell@redhat.com>
… token The shared %destructor for <str_vec> <table_vec> ... called `delete` on each element pointer, but <str_vec> elements are char* allocated by the lexer via strdup() (unquoted IDENTIFIER) or hsql::substr() (quoted IDENTIFIER) — both malloc-backed. Mixing free/delete is undefined behavior. Under tcmalloc with -fsized-deallocation, sized operator delete trusts the static type size (1 for char) and returns the chunk to the wrong size-class freelist, eventually crashing on an unrelated allocation (envoyproxy/envoy#36471). This is the same bug fixed upstream in hyrise#221. Split the destructor: <str_vec> uses free(); the rest hold pointers to new-allocated objects and stay on delete. Also drop the dead DELTA token. It is declared in sql_keywords.txt / bison_parser.y / flex_lexer.l but referenced by no grammar rule, so any SQL using `delta` as an identifier (e.g. pgbench's pgbench_history.delta) fails to parse — which is what trips the destructor cleanup path that triggers the UB above. Regenerate bison_parser.{cpp,h} and flex_lexer.{cpp,h} accordingly. Add regression tests: - DeltaIsAValidIdentifier: confirms `delta` parses as IDENTIFIER. - RepeatedFailedInsertParseDoesNotCorruptHeap: stresses the failed-parse cleanup; under ASAN catches the alloc-dealloc-mismatch immediately on regression. Signed-off-by: Rito Takeuchi <licht-t@outlook.jp>
fixes #220