Discussion:
[Libpqxx-general] Breaks after: _int_malloc: Assertion `(unsigned long)(size) >= (unsigned long)(nb)' failed.
Glus Xof
2012-05-01 18:31:28 UTC
Permalink
Hi,

My app compiled under GNU/Linux breaks with a message as follows,

serverd: malloc.c:4631: _int_malloc: Assertion `(unsigned long)(size)
= (unsigned long)(nb)' failed.
Program received signal SIGABRT, Aborted.
0xb7751424 in __kernel_vsyscall ()

(gdb) bt
#0 0xb7751424 in __kernel_vsyscall ()
#1 0xb7221941 in raise () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
#2 0xb7224d72 in abort () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
#3 0xb7265424 in ?? () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
#4 0xb7267fb9 in ?? () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
#5 0xb7269c0c in malloc () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
#6 0xb726d140 in strdup () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
#7 0xb71a2880 in ?? () from /usr/lib/libpq.so.5
#8 0xb71a2c80 in ?? () from /usr/lib/libpq.so.5
#9 0xb71a4f98 in PQconnectStart () from /usr/lib/libpq.so.5
#10 0xb71a5042 in PQconnectdb () from /usr/lib/libpq.so.5
#11 0xb74ca79d in pqxx::connectionpolicy::normalconnect(pg_conn*) ()
from /usr/lib/libpqxx-3.1.so
#12 0xb74ca966 in pqxx::connect_direct::do_startconnect(pg_conn*) ()
from /usr/lib/libpqxx-3.1.so
#13 0xb74bd855 in pqxx::connection_base::init() () from /usr/lib/libpqxx-3.1.so
#14 0x0805693f in basic_connection (opt=..., this=<optimized out>) at
/usr/include/pqxx/basic_connection.hxx:60
#15 Serverd::_0001 (this=0xbfd4c764) at _0001.cc:9
#16 0x08054bcd in Serverd::accept (this=0xbfd4c764) at connections.cc:80
#17 0x0804c290 in main (argc=1, argv=0xbfd4c9e4) at main.cc:26
(gdb)

Here are some additional info,

// First lines of Serverd::_0001.cc
#include "./serverd.h"

bool Serverd::_0001()
{
bool adminuser = false;

try
{
pqxx::connection pConn (conn_chain); // This is the
line 9 pointed
by the backtrace...

pqxx::noticer * nProcessor = new pqxx::nonnoticer;
pConn.set_noticer (std::auto_ptr<pqxx::noticer> (nProcessor));

pqxx::work pWork (pConn);
[...]
//

$ pkg-config --modversion libpqxx
3.1

What would be the most probably cause of this problem ??
Do you need more info ??

Glus
Jeroen Vermeulen
2012-05-02 03:37:30 UTC
Permalink
Post by Glus Xof
My app compiled under GNU/Linux breaks with a message as follows,
serverd: malloc.c:4631: _int_malloc: Assertion `(unsigned long)(size)
= (unsigned long)(nb)' failed.
Sounds like you may have a memory corruption problem, where the process
writes to a dud pointer somewhere, or a threading problem. But those
are just guesses; there's not enough information to say anything more
definite. Certainly the code you showed us ("create a connection")
should be stable and it's been tested on a wide range of platforms.
Assuming, that is, that conn_chain is either a C++ string or a pointer
to a properly delimited C string that is still allocated and hasn't
overrun its available space.

The first thing to do before posting code is to whittle it down to the
very smallest program that will reproduce the bug. With the types of
bugs I mentioned though, there is no guarantee that the line of code
that introduces the crash is also the source of the problem.

Try compiling your program on various compilers (g++, clang++) with all
warnings enabled, and fix any problems they report. If that doesn't
help, run the program through valgrind to detect memory-management bugs.
Build a version against libmudflap and run it through your test suite
to check for array bounds.

For g++ and clang++, the -Wall option will enable a lot of warnings but
not all. Have a look at the options used when building libpqxx. Also
try different optimization levels: if the problem goes away with -O0
then you've probably got some code in your application that triggers
undefined behaviour. At -O3 the compiler may find structural problems
that it can warn about.


Jeroen

Loading...