Date: Tue, 13 Mar 2012 11:08:40 +0100 From: Alexandre Martins <alexandre.martins@netasq.com> To: freebsd-current@freebsd.org Cc: Konstantin Belousov <kostikbel@gmail.com> Subject: Re: Double free() in libc or gdb ? Message-ID: <201203131108.43815.alexandre.martins@netasq.com> In-Reply-To: <20120312175555.GE75778@deviant.kiev.zoral.com.ua> References: <201203121750.36937.alexandre.martins@netasq.com> <20120312175555.GE75778@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
--nextPart12734491.3e0kVfQm9N Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable On Monday 12 March 2012 18:55:55 Konstantin Belousov wrote: > On Mon, Mar 12, 2012 at 05:50:33PM +0100, Alexandre Martins wrote: > > Dear all, > >=20 > > I'm currently having some trouble with the dynamic loader. > >=20 > > I have the libc compilled with "MALLOC_DEBUG" flag to detect double fre= e. > > When i run this piece of code (attached file) thought GDB, i have this > > assertion : > >=20 > > Assertion failed: ((run->regs_mask[elm] & (1U << bit)) =3D=3D 0), funct= ion > > arena_run_reg_dalloc, file /usr/src/lib/libc/stdlib/malloc.c, line 2543. > >=20 > > But when i run the same binary without GDB, no assert. > >=20 > > I'm very confused. Can you help me to debug that ? >=20 > There is no attachment. Put the source somewhere on web. Sorry, I'll past code here : first.c: ____________________ #include <stdio.h> void print_name(void) { printf("I'm " __FILE__ " at line %d\n", __LINE__); } ____________________ second.c ____________________ #include <stdio.h> void second_name(void) { printf("I'm " __FILE__ " at line %d\n", __LINE__); } void print_name(void) { printf("I'm " __FILE__ " at line %d\n", __LINE__); } ____________________ main.c ____________________ #include <stdio.h> #include <dlfcn.h> extern void print_name(void); int main(int argc, char *argv[]) { void (*second_name)(void); void *handle; int count =3D 0; while(42) { print_name(); handle =3D dlopen("second.so", RTLD_NOW); print_name(); if (handle !=3D NULL) { second_name =3D dlsym(handle, "second_name"); if (second_name !=3D NULL) { printf("second : "); second_name(); } dlclose(handle); } else fprintf(stderr, "Error : %s\n", dlerror()); } } ____________________ Compilation and execution : gcc -shared -O0 -g second.c -o second.so gcc -shared -O0 -g first.c -o libfirst.so gcc -O0 -g toto.c -lfirst -L. -o test export LD_LIBRARY_PATH=3D$PWD gdb ./test Thank you for your help =2D-=20 Alexandre Martins NETASQ -- We secure IT --nextPart12734491.3e0kVfQm9N--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203131108.43815.alexandre.martins>