Browse Source

fixed memory leak in CSVParser::parse() - a Space struct was allocated but never freed

pull/4/head
Tomasz Sowa 1 month ago
parent
commit
f8d24de386
  1. 26
      Makefile
  2. 12
      src/csv/csvparser.cpp
  3. 4
      src/csv/csvparser.h

26
Makefile

@ -18,10 +18,28 @@ tests: FORCE
tests-gcc10: FORCE
env CXX=g++10 CXXFLAGS="-Wl,-rpath=/usr/local/lib/gcc10/ -Wall -pedantic -O0 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C src
env CXX=g++10 CXXFLAGS="-Wl,-rpath=/usr/local/lib/gcc10/ -Wall -pedantic -O0 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C tests
#env CXX=clang++ CXXFLAGS="-fsanitize=address -Wall -pedantic -O0 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C src
#env CXX=clang++ CXXFLAGS="-fsanitize=address -Wall -pedantic -O0 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C tests
env CXX=g++10 CXXFLAGS="-Wl,-rpath=/usr/local/lib/gcc10/ -Wall -pedantic -O0 -g3 -std=c++20 -fmax-errors=1 -I../src -I/usr/local/include" $(MAKE) -C src
env CXX=g++10 CXXFLAGS="-Wl,-rpath=/usr/local/lib/gcc10/ -Wall -pedantic -O0 -g3 -std=c++20 -fmax-errors=1 -I../src -I/usr/local/include" $(MAKE) -C tests
tests-clang: FORCE
env CXX=clang++ CXXFLAGS="-Wall -pedantic -O0 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C src
env CXX=clang++ CXXFLAGS="-Wall -pedantic -O0 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C tests
tests-clang-sa: FORCE
env CXX=clang++ CXXFLAGS="-fsanitize=address -Wall -pedantic -O0 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C src
env CXX=clang++ CXXFLAGS="-fsanitize=address -Wall -pedantic -O0 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C tests
tests-clang-sm: FORCE
env CXX=clang++ CXXFLAGS="-fsanitize=memory -Wall -pedantic -O3 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C src
env CXX=clang++ CXXFLAGS="-fsanitize=memory -Wall -pedantic -O3 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C tests
tests-clang-su: FORCE
env CXX=clang++ CXXFLAGS="-fsanitize=undefined -Wall -pedantic -O3 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C src
env CXX=clang++ CXXFLAGS="-fsanitize=undefined -Wall -pedantic -O3 -g3 -std=c++20 -I../src -I/usr/local/include" $(MAKE) -C tests
clean: FORCE

12
src/csv/csvparser.cpp

@ -161,16 +161,16 @@ void CSVParser::parse()
*
*/
Space * row_space = new Space();
row_space->set_empty_table();
Space row_space;
row_space.set_empty_table();
parse_row(row_space);
space->add(row_space);
space->add(std::move(row_space));
}
}
void CSVParser::parse_row(Space * row_space)
void CSVParser::parse_row(Space & row_space)
{
bool continue_reading;
@ -182,9 +182,9 @@ void CSVParser::parse_row(Space * row_space)
}
bool CSVParser::read_value_to(Space * row_space)
bool CSVParser::read_value_to(Space & row_space)
{
Space & space_value = row_space->add_empty_space();
Space & space_value = row_space.add_empty_space();
space_value.set_empty_wstring();
if( lastc == '"' )

4
src/csv/csvparser.h

@ -135,9 +135,9 @@ protected:
void parse();
void parse_row(Space * row_space);
void parse_row(Space & row_space);
bool read_value_to(Space * row_space);
bool read_value_to(Space & row_space);
bool read_quoted_value_to(std::wstring & value);
bool read_non_quoted_value_to(std::wstring & value);

Loading…
Cancel
Save