[sqlite] Newbie issue - Linux error malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)

2015-06-09 Thread George
On Sun, 7 Jun 2015 21:36:51 +0200
George  wrote:

> On Sat, 06 Jun 2015 21:14:46 +0700
> Dan Kennedy  wrote:
> 
> > On 06/06/2015 03:19 AM, George wrote:
> > > Hello everyone,
> > >
> > > I am new to the list. I am working on an application in which I
> > > will be embedding SQLite as the database engine. The application
> > > is written in C.
> > >
> > > I am currently having an issue which I am not able to resolve at
> > > the moment so I thought I would ask here since I am just starting
> > > out with SQLite.
> > >
> > > My problem is, from my point of view, that I am not able to
> > > perform an action to the same database file in the following
> > > manner:
> > >
> > > 1) I open a database via:
> > >   sqlite3_initialize()
> > >   sqlite3_open_v2
> > > 2) I do some work on getting metadata from the database like table
> > > names and their fields and then
> > > 3) I close the connection via:
> > >   sqlite3_close_v2
> > >   sqlite3_shutdown
> > > 4) After all of this is done I wish to process an import file so I
> > > need to open another connection to the same database file and run
> > > some statements but when I try to do that I get this on the open
> > > call in step 1 (above):
> > 
> > I guess that assert() failing means the heap is corrupted. Which
> > might be SQLite related or might not.
> > 
> > Running the app under [valgrind] might tell you more. Post its
> > complete output here if there are errors but it's not obvious what
> > the problem is.
> > 
> > Dan.
> 
> Thanks to everyone who answered!
> 
> I am doing this on Linux not on an embedded system, Ubuntu 14.04 LTS
> to be more precise.
> 
> I removed the initialize and shutdown which I had wrapped into my
> connect and close methods after reading the "Using SQLite" book and
> probably misunderstanding it...
> 
> The problem is still there even after I removed the 2 function calls.
> 
> I ran the whole app under the valgrind memory checker and it and
> valgrind crashed at the end when the explosion happens. Here is the
> summary:
> 
> ==6013== HEAP SUMMARY:
> ==6013== in use at exit: 0 bytes in 0 blocks
> ==6013==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
> ==6013== 
> ==6013== All heap blocks were freed -- no leaks are possible
> ==6013== 
> ==6013== For counts of detected and suppressed errors, rerun with: -v
> ==6013== Use --track-origins=yes to see where uninitialised values
> come from ==6013== ERROR SUMMARY: 2113 errors from 137 contexts
> (suppressed: 0 from 0)
> Aborted (core dumped)
> make: *** [vg-check-import] Error 134
> 
> I do check the return codes and print any errors with sqlite3_errmsg
> to see if I can move into another direction.
> 
> I also checked my code and I do finalize my statement before the
> close.
> 
> It seems that when I go second time around things go bad...
> 
> Not sure what is going on here...
> Looking ...
> Thanks guys,
> George

Well just for the record. This was a self inflicted problem I had made
a call to a function which did not finalize a statement... once that
was fixed everything works as expected.
Thanks again.

> 
> > 
> > 
> > 
> > 
> > >
> > > malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr)
> > > (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof
> > > (struct malloc_chunk, fd && old_size == 0) || ((unsigned long)
> > > (old_size)
> > >> = (unsigned long)__builtin_offsetof (struct malloc_chunk,
> > >> fd_nextsize))+((2 *(sizeof(size_t)) < __alignof__ (long double) ?
> > >> __alignof__ (long double) : 2 *(sizeof(size_t))) - 1)) & ~((2
> > >> *(sizeof(size_t)) < __alignof__ (long double) ? __alignof__ (long
> > >> double) : 2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1)
> > >> && ((unsigned long) old_end & pagemask) == 0)' failed. Aborted
> > >> (core dumped)
> > > This happens in on line 17149 when calling:
> > >
> > > p = SQLITE_MALLOC( nByte+8 )
> > >
> > > nByte is 64000
> > >
> > > in sqlite3.c (amalgamation latest version
> > > sqlite-amalgamation-3081002.zip)
> > >
> > > I am compiling and running the code on:
> > > Linux x140e 3.13.0-53-generic #89-Ubuntu SMP Wed May 20 10:34:28
> > > UTC 2015 i686 athlon i686 GNU/Linux
> > >
> > > NAME="Ubuntu"
> > > VERSION="14.04.2 LTS, Trusty Tahr"
> > > ID=ubuntu
> > > ID_LIKE=debian
> > > PRETTY_NAME="Ubuntu 14.04.2 LTS"
> > > VERSION_ID="14.04"
> > > HOME_URL="http://www.ubuntu.com/;
> > > SUPPORT_URL="http://help.ubuntu.com/;
> > > BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/;
> > >
> > > I have compiled sqlite.o with the following:
> > >
> > > gcc -c -Wall -O0 -g -std=c99 -Dlinux -I/usr/local/include
> > > sqlite3.c \ -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION -o
> > > obj/sqlite3.o
> > >
> > > Any suggestions or directions greatly appreciated.
> > > TIA,
> > > George
> > > ___
> > > sqlite-users mailing list
> > > sqlite-users at mailinglists.sqlite.org
> > > 

[sqlite] Newbie issue - Linux error malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)

2015-06-07 Thread George
On Sat, 06 Jun 2015 21:14:46 +0700
Dan Kennedy  wrote:

> On 06/06/2015 03:19 AM, George wrote:
> > Hello everyone,
> >
> > I am new to the list. I am working on an application in which I
> > will be embedding SQLite as the database engine. The application is
> > written in C.
> >
> > I am currently having an issue which I am not able to resolve at the
> > moment so I thought I would ask here since I am just starting out
> > with SQLite.
> >
> > My problem is, from my point of view, that I am not able to perform
> > an action to the same database file in the following manner:
> >
> > 1) I open a database via:
> > sqlite3_initialize()
> > sqlite3_open_v2
> > 2) I do some work on getting metadata from the database like table
> > names and their fields and then
> > 3) I close the connection via:
> > sqlite3_close_v2
> > sqlite3_shutdown
> > 4) After all of this is done I wish to process an import file so I
> > need to open another connection to the same database file and run
> > some statements but when I try to do that I get this on the open
> > call in step 1 (above):
> 
> I guess that assert() failing means the heap is corrupted. Which
> might be SQLite related or might not.
> 
> Running the app under [valgrind] might tell you more. Post its
> complete output here if there are errors but it's not obvious what
> the problem is.
> 
> Dan.

Thanks to everyone who answered!

I am doing this on Linux not on an embedded system, Ubuntu 14.04 LTS to
be more precise.

I removed the initialize and shutdown which I had wrapped into my
connect and close methods after reading the "Using SQLite" book and
probably misunderstanding it...

The problem is still there even after I removed the 2 function calls.

I ran the whole app under the valgrind memory checker and it and
valgrind crashed at the end when the explosion happens. Here is the
summary:

==6013== HEAP SUMMARY:
==6013== in use at exit: 0 bytes in 0 blocks
==6013==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==6013== 
==6013== All heap blocks were freed -- no leaks are possible
==6013== 
==6013== For counts of detected and suppressed errors, rerun with: -v
==6013== Use --track-origins=yes to see where uninitialised values come
from ==6013== ERROR SUMMARY: 2113 errors from 137 contexts (suppressed:
0 from 0)
Aborted (core dumped)
make: *** [vg-check-import] Error 134

I do check the return codes and print any errors with sqlite3_errmsg to
see if I can move into another direction.

I also checked my code and I do finalize my statement before the close.

It seems that when I go second time around things go bad...

Not sure what is going on here...
Looking ...
Thanks guys,
George


> 
> 
> 
> 
> >
> > malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr)
> > (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof
> > (struct malloc_chunk, fd && old_size == 0) || ((unsigned long)
> > (old_size)
> >> = (unsigned long)__builtin_offsetof (struct malloc_chunk,
> >> fd_nextsize))+((2 *(sizeof(size_t)) < __alignof__ (long double) ?
> >> __alignof__ (long double) : 2 *(sizeof(size_t))) - 1)) & ~((2
> >> *(sizeof(size_t)) < __alignof__ (long double) ? __alignof__ (long
> >> double) : 2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) &&
> >> ((unsigned long) old_end & pagemask) == 0)' failed. Aborted (core
> >> dumped)
> > This happens in on line 17149 when calling:
> >
> > p = SQLITE_MALLOC( nByte+8 )
> >
> > nByte is 64000
> >
> > in sqlite3.c (amalgamation latest version
> > sqlite-amalgamation-3081002.zip)
> >
> > I am compiling and running the code on:
> > Linux x140e 3.13.0-53-generic #89-Ubuntu SMP Wed May 20 10:34:28 UTC
> > 2015 i686 athlon i686 GNU/Linux
> >
> > NAME="Ubuntu"
> > VERSION="14.04.2 LTS, Trusty Tahr"
> > ID=ubuntu
> > ID_LIKE=debian
> > PRETTY_NAME="Ubuntu 14.04.2 LTS"
> > VERSION_ID="14.04"
> > HOME_URL="http://www.ubuntu.com/;
> > SUPPORT_URL="http://help.ubuntu.com/;
> > BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/;
> >
> > I have compiled sqlite.o with the following:
> >
> > gcc -c -Wall -O0 -g -std=c99 -Dlinux -I/usr/local/include sqlite3.c
> > \ -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION -o
> > obj/sqlite3.o
> >
> > Any suggestions or directions greatly appreciated.
> > TIA,
> > George
> > ___
> > sqlite-users mailing list
> > sqlite-users at mailinglists.sqlite.org
> > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> 
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



[sqlite] Newbie issue - Linux error malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)

2015-06-06 Thread Dan Kennedy
On 06/06/2015 03:19 AM, George wrote:
> Hello everyone,
>
> I am new to the list. I am working on an application in which I will be
> embedding SQLite as the database engine. The application is written in
> C.
>
> I am currently having an issue which I am not able to resolve at the
> moment so I thought I would ask here since I am just starting out with
> SQLite.
>
> My problem is, from my point of view, that I am not able to perform an
> action to the same database file in the following manner:
>
> 1) I open a database via:
>   sqlite3_initialize()
>   sqlite3_open_v2
> 2) I do some work on getting metadata from the database like table
> names and their fields and then
> 3) I close the connection via:
>   sqlite3_close_v2
>   sqlite3_shutdown
> 4) After all of this is done I wish to process an import file so I need
> to open another connection to the same database file and run some
> statements but when I try to do that I get this on the open call in
> step 1 (above):

I guess that assert() failing means the heap is corrupted. Which might 
be SQLite related or might not.

Running the app under [valgrind] might tell you more. Post its complete 
output here if there are errors but it's not obvious what the problem is.

Dan.




>
> malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)
> &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
> malloc_chunk, fd && old_size == 0) || ((unsigned long) (old_size)
>> = (unsigned long)__builtin_offsetof (struct malloc_chunk,
>> fd_nextsize))+((2 *(sizeof(size_t)) < __alignof__ (long double) ?
>> __alignof__ (long double) : 2 *(sizeof(size_t))) - 1)) & ~((2
>> *(sizeof(size_t)) < __alignof__ (long double) ? __alignof__ (long
>> double) : 2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) &&
>> ((unsigned long) old_end & pagemask) == 0)' failed. Aborted (core
>> dumped)
> This happens in on line 17149 when calling:
>
> p = SQLITE_MALLOC( nByte+8 )
>
> nByte is 64000
>
> in sqlite3.c (amalgamation latest version
> sqlite-amalgamation-3081002.zip)
>
> I am compiling and running the code on:
> Linux x140e 3.13.0-53-generic #89-Ubuntu SMP Wed May 20 10:34:28 UTC
> 2015 i686 athlon i686 GNU/Linux
>
> NAME="Ubuntu"
> VERSION="14.04.2 LTS, Trusty Tahr"
> ID=ubuntu
> ID_LIKE=debian
> PRETTY_NAME="Ubuntu 14.04.2 LTS"
> VERSION_ID="14.04"
> HOME_URL="http://www.ubuntu.com/;
> SUPPORT_URL="http://help.ubuntu.com/;
> BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/;
>
> I have compiled sqlite.o with the following:
>
> gcc -c -Wall -O0 -g -std=c99 -Dlinux -I/usr/local/include sqlite3.c \
>  -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION -o obj/sqlite3.o
>
> Any suggestions or directions greatly appreciated.
> TIA,
> George
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



[sqlite] Newbie issue - Linux error malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)

2015-06-06 Thread Simon Slavin

On 5 Jun 2015, at 9:19pm, George  wrote:

> 1) I open a database via:
>   sqlite3_initialize()
>   sqlite3_open_v2
> 2) I do some work on getting metadata from the database like table
> names and their fields and then
> 3) I close the connection via:
>   sqlite3_close_v2
>   sqlite3_shutdown

There's no need to call _initialize().  It won't do any harm, but there's no 
need for it.  The code in _open_v2() checks for it and calls it if you haven't 
already.

If your application is going to do more SQLite, don't call _shutdown().  If you 
have already closed your database connections the amount of resources released 
is negligible and the _shutdown() and _reinitialize() pair can take quite a 
long time to execute.  You can actually forget to call _shutdown() alltogether. 
 All it does is release resources which will be released automatically when 
your program quits.

With all the calls you listed above, are you checking the results returned to 
make sure they're equal to SQLITE_OK ?

If the code in your step (2) includes any statements (e.g. if you use 
_prepare/_step) then are you finalizing each statement before you use _close() 
?  Are you checking the values returned by _finalize() to make sure they're 
SQLITE_OK ?

Simon.


[sqlite] Newbie issue - Linux error malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)

2015-06-06 Thread Keith Medcalf

What embedded OS are you using?  {Perhaps your INIT and SHUTDOWN 
procedures/code is incorrect}. 

If you are not using an embedded OS, why are you calling sqlite3_initialize and 
sqlite3_shutdown?  You do realize that the purpose of sqlite3_shutdown is to 
indicate that you no longer require the use of the sqlite engine in the current 
process because you are, well, finished with it?


> -Original Message-
> From: sqlite-users-bounces at mailinglists.sqlite.org [mailto:sqlite-users-
> bounces at mailinglists.sqlite.org] On Behalf Of George
> Sent: Friday, 5 June, 2015 14:19
> To: sqlite-users at mailinglists.sqlite.org
> Subject: [sqlite] Newbie issue - Linux error malloc.c:2372: sysmalloc:
> Assertion `(old_top == (((mbinptr) (((char *)
> 
> Hello everyone,
> 
> I am new to the list. I am working on an application in which I will be
> embedding SQLite as the database engine. The application is written in
> C.
> 
> I am currently having an issue which I am not able to resolve at the
> moment so I thought I would ask here since I am just starting out with
> SQLite.
> 
> My problem is, from my point of view, that I am not able to perform an
> action to the same database file in the following manner:
> 
> 1) I open a database via:
>   sqlite3_initialize()
>   sqlite3_open_v2
> 2) I do some work on getting metadata from the database like table
> names and their fields and then
> 3) I close the connection via:
>   sqlite3_close_v2
>   sqlite3_shutdown
> 4) After all of this is done I wish to process an import file so I need
> to open another connection to the same database file and run some
> statements but when I try to do that I get this on the open call in
> step 1 (above):
> 
> malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)
> &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
> malloc_chunk, fd && old_size == 0) || ((unsigned long) (old_size)
> >= (unsigned long)__builtin_offsetof (struct malloc_chunk,
> >fd_nextsize))+((2 *(sizeof(size_t)) < __alignof__ (long double) ?
> >__alignof__ (long double) : 2 *(sizeof(size_t))) - 1)) & ~((2
> >*(sizeof(size_t)) < __alignof__ (long double) ? __alignof__ (long
> >double) : 2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) &&
> >((unsigned long) old_end & pagemask) == 0)' failed. Aborted (core
> >dumped)
> 
> This happens in on line 17149 when calling:
> 
> p = SQLITE_MALLOC( nByte+8 )
> 
> nByte is 64000
> 
> in sqlite3.c (amalgamation latest version
> sqlite-amalgamation-3081002.zip)
> 
> I am compiling and running the code on:
> Linux x140e 3.13.0-53-generic #89-Ubuntu SMP Wed May 20 10:34:28 UTC
> 2015 i686 athlon i686 GNU/Linux
> 
> NAME="Ubuntu"
> VERSION="14.04.2 LTS, Trusty Tahr"
> ID=ubuntu
> ID_LIKE=debian
> PRETTY_NAME="Ubuntu 14.04.2 LTS"
> VERSION_ID="14.04"
> HOME_URL="http://www.ubuntu.com/;
> SUPPORT_URL="http://help.ubuntu.com/;
> BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/;
> 
> I have compiled sqlite.o with the following:
> 
> gcc -c -Wall -O0 -g -std=c99 -Dlinux -I/usr/local/include sqlite3.c \
> -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION -o obj/sqlite3.o
> 
> Any suggestions or directions greatly appreciated.
> TIA,
> George
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users





[sqlite] Newbie issue - Linux error malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)

2015-06-05 Thread George
Hello everyone,

I am new to the list. I am working on an application in which I will be
embedding SQLite as the database engine. The application is written in
C.

I am currently having an issue which I am not able to resolve at the
moment so I thought I would ask here since I am just starting out with
SQLite.

My problem is, from my point of view, that I am not able to perform an
action to the same database file in the following manner:

1) I open a database via:
sqlite3_initialize()
sqlite3_open_v2
2) I do some work on getting metadata from the database like table
names and their fields and then
3) I close the connection via:
sqlite3_close_v2
sqlite3_shutdown
4) After all of this is done I wish to process an import file so I need
to open another connection to the same database file and run some
statements but when I try to do that I get this on the open call in
step 1 (above):

malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)
&((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
malloc_chunk, fd && old_size == 0) || ((unsigned long) (old_size)
>= (unsigned long)__builtin_offsetof (struct malloc_chunk,
>fd_nextsize))+((2 *(sizeof(size_t)) < __alignof__ (long double) ?
>__alignof__ (long double) : 2 *(sizeof(size_t))) - 1)) & ~((2
>*(sizeof(size_t)) < __alignof__ (long double) ? __alignof__ (long
>double) : 2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) &&
>((unsigned long) old_end & pagemask) == 0)' failed. Aborted (core
>dumped)

This happens in on line 17149 when calling:

p = SQLITE_MALLOC( nByte+8 )

nByte is 64000

in sqlite3.c (amalgamation latest version
sqlite-amalgamation-3081002.zip)

I am compiling and running the code on:
Linux x140e 3.13.0-53-generic #89-Ubuntu SMP Wed May 20 10:34:28 UTC
2015 i686 athlon i686 GNU/Linux

NAME="Ubuntu"
VERSION="14.04.2 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.2 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/;
SUPPORT_URL="http://help.ubuntu.com/;
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/;

I have compiled sqlite.o with the following:

gcc -c -Wall -O0 -g -std=c99 -Dlinux -I/usr/local/include sqlite3.c \
-DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION -o obj/sqlite3.o

Any suggestions or directions greatly appreciated.
TIA,
George