Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
env:
CC: ${{matrix.cc}}
CXX: ${{matrix.cxx}}
CXXFLAGS: ${{matrix.env_cxxflags}}
LDFLAGS: ${{matrix.env_ldflags}}
defaults:
run:
shell: bash
Expand Down Expand Up @@ -46,9 +48,24 @@ jobs:
cxx: clang++
os: macos-latest

- name: clang-sanitizer-ubuntu
cc: clang-19
cxx: clang++-19
os: ubuntu-latest
container: ubuntu:24.04
env_cxxflags: "-fsanitize=address,undefined"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we need this additional "runs" (whatever those are called) here. Can't we have that as a last step on the existing clang runs (name: clang-19 and name: clang-macOS)?

env_ldflags: "-fsanitize=address,undefined"

- name: clang-sanitizer-macOS
cc: clang
cxx: clang++
os: macos-latest
env_cxxflags: "-fsanitize=address,undefined"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had a deeper look, but this thread describes the same issue as with the latest CI run: https://stackoverflow.com/a/40215639/1147726

env_ldflags: "-fsanitize=address,undefined"

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
if: matrix.name != 'gcc-6'

- name: Checkout (Ubuntu 18.04)
Expand All @@ -67,17 +84,17 @@ jobs:
git checkout $GITHUB_HEAD_REF

- name: Setup (macOS)
if: matrix.name == 'clang-macOS'
if: matrix.os == 'macos-latest'
run: |
brew install bison flex
echo "BISON=$(brew --prefix bison)/bin/bison" >> $GITHUB_ENV
echo "FLEX=$(brew --prefix flex)/bin/flex" >> $GITHUB_ENV

- name: Setup (Ubuntu)
if: matrix.name != 'clang-macOS'
if: matrix.os == 'ubuntu-latest'
run: |
apt-get update
apt-get install --no-install-recommends -y bison flex ${CC} ${CXX} make valgrind
apt-get install --no-install-recommends -y bison flex ${CC} ${CXX} make valgrind ${{ matrix.name == 'clang-sanitizer-ubuntu' && 'libclang-rt-19-dev' || '' }}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment for this line? It's not easy to read.
Also, it fixes the library to version 19 which is disconnected from the above definition. Not ideal.

echo "BISON=bison" >> $GITHUB_ENV
echo "FLEX=flex" >> $GITHUB_ENV

Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ GMAKE = make mode=$(mode)
NAME := sqlparser
PARSER_CPP = $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp
PARSER_H = $(SRCPARSER)/bison_parser.h $(SRCPARSER)/flex_lexer.h
LIB_CFLAGS = -std=c++17 $(OPT_FLAG)
LIB_CFLAGS = -std=c++17 $(OPT_FLAG) $(CXXFLAGS)
LIB_LFLAGS = $(LDFLAGS)


relaxed_build ?= "off"
ifeq ($(relaxed_build), on)
Expand All @@ -54,12 +56,12 @@ static ?= no
ifeq ($(static), yes)
LIB_BUILD = lib$(NAME).a
LIBLINKER = $(AR)
LIB_LFLAGS = rs
LIB_LFLAGS += rs
else
LIB_BUILD = lib$(NAME).so
LIBLINKER = $(CXX)
LIB_CFLAGS += -fPIC
LIB_LFLAGS = -shared -o
LIB_LFLAGS += -shared -o
endif
LIB_CPP = $(sort $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(PARSER_CPP))
LIB_H = $(shell find $(SRC) -name '*.h' -not -path "$(SRCPARSER)/*") $(PARSER_H)
Expand Down
4 changes: 3 additions & 1 deletion src/SQLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ bool SQLParser::tokenize(const std::string& sql, std::vector<int16_t>* tokens) {
int16_t token = hsql_lex(&yylval, &yylloc, scanner);
while (token != 0) {
tokens->push_back(token);
token = hsql_lex(&yylval, &yylloc, scanner);

if (token == SQL_IDENTIFIER || token == SQL_STRING) {
free(yylval.sval);
yylval.sval = nullptr;
}
token = hsql_lex(&yylval, &yylloc, scanner);

}

hsql__delete_buffer(state, scanner);
Expand Down
15 changes: 15 additions & 0 deletions test/sql_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ TEST(SQLParserTokenizeStringifyTest) {
ASSERT(query == cache[token_string]);
ASSERT(&query != &cache[token_string]);
}

// Regression test for the memory leak reported in issue #261.
TEST(SQLParserTokenizeLeakRegressionTest) {

const std::string query = "'string_1' 'string_2' 'string_3';";
std::vector<int16_t> tokens;

ASSERT(SQLParser::tokenize(query, &tokens));

ASSERT_EQ(tokens.size(), 4);
ASSERT_EQ(tokens[0], SQL_STRING);
ASSERT_EQ(tokens[1], SQL_STRING);
ASSERT_EQ(tokens[2], SQL_STRING);
ASSERT_EQ(tokens[3], ';');
}
Loading