Hi, ALL, I am trying to create my software with MSVC 2010 and latest SQLite.
Because MSVC reported memory leaks, I tried VLD. Here is their output: [quote] Detected memory leaks! Dumping objects -> {158248} normal block at 0x011EA4B8, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {158164} normal block at 0x011EAAA0, 48 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {153560} normal block at 0x011E8FD8, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {153479} normal block at 0x011AB100, 40 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {152403} normal block at 0x011EA710, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {152143} normal block at 0x011AABD0, 40 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {151376} normal block at 0x011AD190, 40 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {150924} normal block at 0x011E8F78, 32 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {150182} normal block at 0x011AAB10, 56 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {150116} normal block at 0x011EA278, 48 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {149345} normal block at 0x011EC398, 40 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {149218} normal block at 0x011E8E10, 40 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {148638} normal block at 0x011AACA8, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {148424} normal block at 0x011EA450, 40 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {146249} normal block at 0x011E75E0, 40 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {146189} normal block at 0x011E9100, 40 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {145608} normal block at 0x011EA3E0, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {145545} normal block at 0x011ACA10, 48 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {145073} normal block at 0x011AC9A0, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {145010} normal block at 0x011E74C0, 40 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {144532} normal block at 0x011E7450, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {144484} normal block at 0x011E3CA8, 40 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {143252} normal block at 0x011AAE80, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {143102} normal block at 0x011EAB28, 40 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {142797} normal block at 0x011AAC40, 40 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {142710} normal block at 0x011AC940, 32 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {142355} normal block at 0x011E7528, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {142313} normal block at 0x011E91A0, 48 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {141529} normal block at 0x011E7350, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {141487} normal block at 0x011EB738, 48 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {141269} normal block at 0x011EB6D0, 40 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {141145} normal block at 0x011AB098, 40 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {140691} normal block at 0x011AB030, 40 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {140643} normal block at 0x011AD290, 32 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {140226} normal block at 0x011AD220, 48 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {140108} normal block at 0x011E6938, 48 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {139867} normal block at 0x011AB188, 40 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {139816} normal block at 0x011AD130, 32 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {139626} normal block at 0x011E3C40, 40 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {139522} normal block at 0x011E3B50, 32 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 {139426} normal block at 0x011E3AE8, 40 bytes long. Data: <PRAGMA foreign_k> 50 52 41 47 4D 41 20 66 6F 72 65 69 67 6E 5F 6B {139174} normal block at 0x011AC358, 32 bytes long. Data: <PRAGMA table_inf> 50 52 41 47 4D 41 20 74 61 62 6C 65 5F 69 6E 66 Object dump complete. No memory leaks detected. Visual Leak Detector is now exiting. The program '[2176] docview.exe: Native' has exited with code 0 (0x0). [/quote] And here is the code for the function: [code] int SQLiteDatabase::GetTableListFromDb(std::vector<std::wstring> &errorMsg) { std::vector<Field> fields; std::map<int,std::vector<FKField> > foreign_keys; std::wstring errorMessage; sqlite3_stmt *stmt = NULL, *stmt2 = NULL, *stmt3 = NULL; std::string fieldName, fieldType, fieldDefaultValue, fkTable, fkField, fkTableField, fkUpdateConstraint, fkDeleteConstraint; int result = 0, res = SQLITE_OK, res1, res2 = SQLITE_OK, res3 = SQLITE_OK, fieldIsNull, fieldPK, fkReference, autoinc; FK_ONUPDATE update_constraint = NO_ACTION_UPDATE; FK_ONDELETE delete_constraint = NO_ACTION_DELETE; std::string query1 = "SELECT name FROM sqlite_master WHERE type = ?"; std::string query2 = "PRAGMA table_info(\"%w\");"; std::string query3 = "PRAGMA foreign_key_list(\"%w\")"; std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv; if( ( res = sqlite3_prepare_v2( m_db, query1.c_str(), query1.length(), &stmt, 0 ) ) == SQLITE_OK ) { res = sqlite3_bind_text( stmt, 1, "table", -1, SQLITE_STATIC ); if( res == SQLITE_OK ) { for( ; ; ) { res = sqlite3_step( stmt ); if( res == SQLITE_ROW ) { const unsigned char *tableName = sqlite3_column_text( stmt, 0 ); char *z = sqlite3_mprintf( query2.c_str(), tableName ); if( ( res1 = sqlite3_prepare_v2( m_db, z, -1, &stmt2, 0 ) ) == SQLITE_OK ) { for( ; ; ) { res1 = sqlite3_step( stmt2 ); if( res1 == SQLITE_ROW ) { unsigned char *temp; fieldName = reinterpret_cast<const char *>( sqlite3_column_text( stmt2, 1 ) ); if( ( temp = const_cast<unsigned char *>( sqlite3_column_text( stmt2, 2 ) ) ) == NULL ) fieldType = ""; else fieldType = reinterpret_cast<char *>( temp ); fieldIsNull = sqlite3_column_int( stmt2, 3 ); if( ( temp = const_cast<unsigned char *>( sqlite3_column_text( stmt2, 4 ) ) ) == NULL ) fieldDefaultValue = ""; else fieldDefaultValue = reinterpret_cast<char *>( temp ); fieldPK = sqlite3_column_int( stmt2, 5 ); int res = sqlite3_table_column_metadata( m_db, NULL, (const char *) tableName, fieldName.c_str(), NULL, NULL, NULL, NULL, &autoinc ); if( res != SQLITE_OK ) { result = 1; GetErrorMessage( res, errorMessage ); errorMsg.push_back( errorMessage ); break; } fields.push_back( Field( myconv.from_bytes( fieldName ), myconv.from_bytes( fieldType ), 0, 0, myconv.from_bytes( fieldDefaultValue ), fieldIsNull == 0 ? false: true, autoinc == 1 ? true : false, fieldPK == 1 ? true : false ) ); } else if( res1 == SQLITE_DONE ) break; else { result = 1; GetErrorMessage( res, errorMessage ); errorMsg.push_back( errorMessage ); break; } } if( res1 != SQLITE_DONE ) break; } else { result = 1; GetErrorMessage( res, errorMessage ); errorMsg.push_back( errorMessage ); } sqlite3_finalize( stmt2 ); if( res1 == SQLITE_DONE ) { char *y = sqlite3_mprintf( query3.c_str(), tableName ); res2 = sqlite3_prepare( m_db, y, -1, &stmt3, 0 ); if( res2 == SQLITE_OK ) { for( ; ; ) { res3 = sqlite3_step( stmt3 ); if( res3 == SQLITE_ROW ) { fkReference = sqlite3_column_int( stmt3, 1 ); fkTable = reinterpret_cast<const char *>( sqlite3_column_text( stmt3, 2 ) ); fkField = reinterpret_cast<const char *>( sqlite3_column_text( stmt3, 3 ) ); fkTableField = reinterpret_cast<const char *>( sqlite3_column_text( stmt3, 4 ) ); fkUpdateConstraint = reinterpret_cast<const char *>( sqlite3_column_text( stmt3, 5 ) ); if( !strcmp( fkUpdateConstraint.c_str(), "NO ACTION" ) ) update_constraint = NO_ACTION_UPDATE; if( !strcmp( fkUpdateConstraint.c_str(), "RESTRICT" ) ) update_constraint = RESTRICT_UPDATE; if( !strcmp( fkUpdateConstraint.c_str(), "SET NULL" ) ) update_constraint = SET_NULL_UPDATE; if( !strcmp( fkUpdateConstraint.c_str(), "SET DEFAULT" ) ) update_constraint = SET_DEFAULT_UPDATE; if( !strcmp( fkUpdateConstraint.c_str(), "CASCADE" ) ) update_constraint = CASCADE_UPDATE; fkDeleteConstraint = reinterpret_cast<const char *>( sqlite3_column_text( stmt3, 6 ) ); if( !strcmp( fkDeleteConstraint.c_str(), "NO ACTION" ) ) delete_constraint = NO_ACTION_DELETE; if( !strcmp( fkDeleteConstraint.c_str(), "RESTRICT" ) ) delete_constraint = RESTRICT_DELETE; if( !strcmp( fkDeleteConstraint.c_str(), "SET NULL" ) ) delete_constraint = SET_NULL_DELETE; if( !strcmp( fkDeleteConstraint.c_str(), "SET DEFAULT" ) ) delete_constraint = SET_DEFAULT_DELETE; if( !strcmp( fkDeleteConstraint.c_str(), "CASCADE" ) ) delete_constraint = CASCADE_DELETE; foreign_keys[fkReference].push_back( FKField( myconv.from_bytes( fkTable ), myconv.from_bytes( fkField ), myconv.from_bytes( fkTableField ), L"", update_constraint, delete_constraint ) ); } else if( res3 == SQLITE_DONE ) break; else { result = 1; GetErrorMessage( res, errorMessage ); errorMsg.push_back( errorMessage ); break; } } if( res3 != SQLITE_DONE ) break; } else { result = 1; GetErrorMessage( res, errorMessage ); errorMsg.push_back( errorMessage ); } sqlite3_finalize( stmt3 ); } if( res1 == SQLITE_DONE && res3 == SQLITE_DONE ) pimpl->m_tables[m_catalog].push_back( Table( myconv.from_bytes( (const char *) tableName ), fields, foreign_keys ) ); } else if( res == SQLITE_DONE ) break; else { result = 1; GetErrorMessage( res, errorMessage ); errorMsg.push_back( errorMessage ); break; } } } else { result = 1; GetErrorMessage( res, errorMessage ); errorMsg.push_back( errorMessage ); } } else { result = 1; GetErrorMessage( res, errorMessage ); errorMsg.push_back( errorMessage ); } sqlite3_finalize( stmt ); return result; } [/code] Is it a false positive or real memory leaks? If its FP, is there a way to rewrite it to have a clean run? Thank you and sorry for a long e-mail. _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users