c++ - Can't find memory leak detected by Valgrind -
i'm working on program , have memory leak can't nail down. i'm not experienced c/c++ either. i'll post 1 of valgrind errors , class definitions , functions relevant... if forget something, ask , update :) reason not posting of valgrind report there lot of them, similar... difference stack trace has.
i started out designing rather poorly, fix memory leaks, idea create global factory add objects in order delete them later. replaced every occurrence of "new" factory method create it.. in case, class column. i'm positive every object created makecolumn deleted, use vector store pointer. function iterate through vector , delete each item in being called before program ends.
this valgrind report makes me think somehow, string not being unallocated. set glibcxx_force_new variable, , makes no difference in leaks detected. using gcc 4.7.2.
also, yes, receiving information antlr generated parser... not matter, antlr handles it's own memory. char pointers data antlr.
==23168== 15 bytes in 1 blocks lost in loss record 10 of 30 ==23168== @ 0x4ace73c: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==23168== 0x4ba62a3: std::string::_rep::_s_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib32/libstdc++.so.6.0.17) ==23168== 0x4ba75ee: std::string::_rep::_m_clone(std::allocator<char> const&, unsigned int) (in /usr/lib32/libstdc++.so.6.0.17) ==23168== 0x4ba7f3f: std::string::assign(std::string const&) (in /usr/lib32/libstdc++.so.6.0.17) ==23168== 0x4ba7f92: std::string::operator=(std::string const&) (in /usr/lib32/libstdc++.so.6.0.17) ==23168== 0x82e0b57: genericfactory::makecolumn(char const*, char const*, char const*) (global.cpp:246) ==23168== 0x82dea23: addtable (helper.cpp:93) ==23168== 0x810de1f: query_table_expression (oraclesqlparser.c:165181) ==23168== 0x8108f66: table_reference (oraclesqlparser.c:162767) ==23168== 0x81154b1: join_clause (oraclesqlparser.c:168172) ==23168== 0x82a0845: synpred349_oraclesql_fragment (oraclesqlparser.c:460632) ==23168== 0x82afa48: synpred349_oraclesql (oraclesqlparser.c:469414)
helper.cpp:addtable - putvalue adds pointer map.
void addtable(char* schema, char* table) { ::gbl_info->tables->putvalue(::gbl_info->factory.makecolumn(schema,table,""),null); }
genericfactory::makecolumn
column* genericfactory::makecolumn(const char* schema,const char* table, const char* column) { this->count++; column* col = new column(schema,table,column); this->allocated_objects.push_back(col); return col; }
column::column
column::column(const char* schema, const char* table, const char* column) { string temp = schema; this->schema = normalize(temp); temp = table; this->table = normalize(temp); temp = column; this->column = normalize(temp); temp = schema; temp = temp + "." + table + "." + column; this->text = normalize(temp); }
normalize
string& normalize(string& str) { (string::iterator p=str.begin(); p != str.end(); p++) *p = toupper(*p); str.erase(remove(str.begin(),str.end(),'"'),str.end()); // erase double quotes return str; }
column definition: sqldata has no members or constructors
class column : public sqldata { std::string text; std::string schema; std::string table; std::string column; public: std::string alias; // table alias column(const char*,const char*,const char*); column(const std::string qn); //has functions too, irrelevant }
i've spent hours trying fix , i'm not sure i'm losing memory... program can run minutes or hours while processing data, , builds up.
a great way solve problems such 1 (errors of unknown origin), try downloading gcc , throwing code against 'the wall'.
Comments
Post a Comment