The relevant code in 3.7.4 (with assert() statements removed) is as
follows (line numbers o the left):

434 static int isLookaside(sqlite3 *db, void *p){
435   return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
436 }
450 int sqlite3DbMallocSize(sqlite3 *db, void *p){
452   if( db && isLookaside(db, p) ){
453     return db->lookaside.sz;
454   }else{
458     return sqlite3GlobalConfig.m.xSize(p);
459   }
460 }

The isLookaside() function should return false if p==0.   So I do not
see how you might have segfaulted on the db->lookaside.sz expression
of line 453.  And even then, I don't see how such a segfault is
possible if db is still a valid pointer.

Can you please send a stack trace from the point where the original
3.7.4 segfaults?

Also:  What do you mean when you say "I added callback function
pointers to my sqlite database"?  Have you modified the code
someplace?  Or are you using one of the many SQLite APIs that sets
callback functions?  If the latter, can you please tell us which
routines you are using?


On Fri, Jan 7, 2011 at 6:00 PM, <[email protected]> wrote:
>
> 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:
> [email protected] <mailto:[email protected]>
>
>
>
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



--
D. Richard Hipp
[email protected]
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to