Hi SQLite Team

 

I added callback function pointers for my sqlite database and the
program crashed in the function sqlite3DbMallocSize. Same code works
fine with older release such as 3.6.15.

 

I debugged and got the place where the exception was thrown.

 

in 3.7.4

SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){

            assert( db==0 || sqlite3_mutex_held(db->mutex) );

            else if( db && isLookaside(db, p) ){

                        return db->lookaside.sz;

            }else{

                        assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );

                        assert( sqlite3MemdebugHasType(p,
MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );

                        assert( db!=0 || sqlite3MemdebugNoType(p,
MEMTYPE_LOOKASIDE) );

                        return sqlite3GlobalConfig.m.xSize(p);

            }

}

 

while in 3.6.15 it was implemented as 

 

SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){

  assert( db==0 || sqlite3_mutex_held(db->mutex) );

  if( p==0 ){

    return 0;

  }else if( isLookaside(db, p) ){

    return db->lookaside.sz;

  }else{

    return sqlite3GlobalConfig.m.xSize(p);

  }

}

 

So, in order to get my app fly, I modified 3.7.4 sqlite code by adding a
few more lines (in red):

 

SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){

            assert( db==0 || sqlite3_mutex_held(db->mutex) );

            if( p == 0 ) // youfei fixed to prevent  illegal memory
access when callbacks get called

            {

                        return 0;

            }

            else if( db && isLookaside(db, p) ){

                        return db->lookaside.sz;

            }else{

                        assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );

                        assert( sqlite3MemdebugHasType(p,
MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );

                        assert( db!=0 || sqlite3MemdebugNoType(p,
MEMTYPE_LOOKASIDE) );

                        return sqlite3GlobalConfig.m.xSize(p);

            }

}

 

In my code, *p is 0 when sqlite3DbMallocSize gets called, so a memory
access violation exception is thrown by "return
sqlite3GlobalConfig.m.xSize(p);". Previous release covers it well while
the latest does not. After the modification my program gets back to
work. Please verify my change and let me know if it's a bug missed by
you experts?

 

Thanks,

Youfei

 

 

 

 

 

 

 

Youfei Chen | EMC Corporation <http://www.emc.com/>  | 176 South Street
Hopkinton, MA 01748
<http://maps.google.com/maps?f=q&hl=en&geocode=&q=176+South+Street+Hopki
nton,+MA+01748>  | Direct #: (508)293-6402 | Extension: 76402 | Email:
youfei.c...@emc.com <mailto:chen_you...@emc.com>  

 

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to