Red Hat Bugzilla – Bug 623219
gdb aborts with a 'double free or corruption' when calling inferior functions with print or call command
Last modified: 2018-11-14 12:34:48 EST
gdb aborts with a "double free or corruption" when calling inferior functions with print or call command. This occurs only when the inferior function dynamically loads a shared library.
Steps to Reproduce:
1) Create the sample programs:
int add(int a, int b)
using namespace std;
extern "C" int openlibrary()
void* handle = dlopen ("./libmyshared.so", RTLD_LAZY);
if (handle != NULL)
2) Build the program:
$ g++ -g -m32 -shared -o libmyshared.so shared.cpp
$ g++ -g -m32 main.cpp -ldl
$ gdb a.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
For bug reporting instructions, please see:
Reading symbols from /root/test_gdb_new/a.out...done.
(gdb) break main
Breakpoint 1 at 0x8048762: file main.cpp, line 21.
Starting program: /root/test_gdb_new/a.out
Breakpoint 1, main () at main.cpp:21
21 return 0;
(gdb) p openlibrary()
$1 = 0
*** glibc detected *** gdb: double free or corruption (!prev): 0x0943e998 ***
gdb should not crash.
The same test works correctly on Fedora-13 with gdb-7.1-28.fc13
This patch seems to work for me and I didn't seem to have broken anything after running make check.
It's a backport of this patch http://osdir.com/ml/general/2010-03/msg18913.html
Created attachment 438221 [details]
Re: RFC: fix bug with std::terminate handler
Created attachment 439338 [details]
[patch] testsuite: new: std::terminate crash
* Mon Sep 6 2010 Jan Kratochvil <firstname.lastname@example.org> - 7.0.1-27.el5
- Fix crash with std::terminate handler (BZ 623219, Tom Tromey).
Technical note added. If any revisions are required, please edit the "Technical Notes" field
accordingly. All revisions will be proofread by the Engineering Content Services team.
Previously, GDB terminated unexpectedly when an inferior shared library list changed during an inferior function call, for example by the dlopen() function. With this update, GDB remains stable in this case.
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.