This project has moved. For the latest updates, please go here.

False positive detection

Nov 4, 2012 at 8:33 AM
Edited Nov 4, 2012 at 8:34 AM

Hi, ALL,

I'm currently working on the project which involves communicating with SQLite database.

The project utilizes wxWidgets and it uses MSVS 2010.

During the debugging MSVS reported memory leaks.

 

Forgot to add that I am using the latest 2.2.3 version, the one that is available for download.

In order to find out I googled and found this project. I downloaded, installed it but now every single call to SQLite function is reported as having a memory leak.

 

Can someone please look into it?

Following C++ function reports memory leak (as an example):

 

{

    char *error;
    int result = sqlite3_open( dbName, &m_handle );
    if( result == SQLITE_OK )
    {
        if( sqlite3_exec( m_handle, "PRAGMA foreign_keys = ON", NULL, NULL, &error ) != SQLITE_OK )
            wxMessageBox( "Internal database failure. Can't set database parameter for foreign key" );
        else
            m_connected = true;
    }

}


 

Thank you.

Coordinator
Nov 7, 2012 at 10:45 PM

Can you provide me minimal project that reproduce that problem?

Nov 7, 2012 at 11:28 PM

Hi, KindDragon,

I have a wxWidgets C++ project which uses SQLite. It is built with MSVC 2010.

Basically all you need is this:

1. Download sqlite3 amalgamation packet which contains the source code of sqlite3

2. Create a C++ project or C project for that matter.

3. In the main() put following code:

 

int main()

{

          sqlite3 *handle;

          sqlite3_stmt *stmt;

          int result = sqlite3_open( "database.db", &handle );

          if( result == SQLITE_OK )

         {

                      if( sqlite3_prepare_v2( handle, "CREATE TABLE test( id INTEGER, name CHAR( 10 ) );", -1, &stmt, 0 ) == SQLITE_OK )

                     {

                                sqlite3_step( stmt );

                                sqlite3_finalize( stmt );

                     }

         }

        sqlite3_close( handle );

}

 

Attach "vld" to the project, compile and run.

You will get a lot of memory leaks on the "sqlite3_open()" and "sqlite3_prepare_v2()" calls.

However, "sqlite3_finalize( stmt );" line should take care of all memory allocations that had been done on the code.

 

If you will not get any leaks let me know and I will try to provide the code along with the simple db to replicate.

If you do, let me know as well so that I know this is not something specific to wxWidgets.

 

Thank you.

 

P.S.: One suggestion  (a little off-topic): it would be nice if there will be some instructions on how to remove VLD from Visual Studio.

I tried to just remove the line "#include "vld.h", but when running the project under the debugger it has been stuck on exit as if it searches for the VLD DLL's.

Mar 13, 2013 at 11:43 AM
VLD flagged every call to an sqlite3 routine which calls SQLITE_MALLOC, such as

p = SQLITE_MALLOC( nByte+8 );

However, sqlite3.c contains the following code which VLD seems to ignore, hence the reported leaks.
/*
** Like free() but works for allocations obtained from sqlite3MemMalloc()
** or sqlite3MemRealloc().
**
** For this low-level routine, we already know that pPrior!=0 since
** cases where pPrior==0 will have been intecepted and dealt with
** by higher-level routines.
*/

static void sqlite3MemFree(void *pPrior){
#ifdef SQLITE_MALLOCSIZE
  SQLITE_FREE(pPrior);
#else
  sqlite3_int64 *p = (sqlite3_int64*)pPrior;
  assert( pPrior!=0 );
  p--;
  SQLITE_FREE(p);
#endif
I hope this helps in clearing the situation.