STL bug?

Wagner Dias dias@www.ansp.br
Thu Jan 28 12:25:00 GMT 1999


Hi,

I think I detected a memory leak problem in STL. I'm sending a simple
example to show it.

I used the ccmalloc library to report the memory leak (ccmalloc can be
found at http://iseran.ira.uka.de/~armin/ccmalloc/ ). Below I show the
reports generated by ccmalloc.

I'm running egcs version egcs-2.91.60 19981201 (egcs-1.1.1 release), on
RedHat 5.2.

Please mail your test results. I would appreciate it a lot.

Thanks in advance,

Dias

------------
Report of the execution of the program replacing BIG in the marked line of
example.cc by SMALL:

.--------------------------------------------------------------------------.
|================ ccmalloc-0.2.3 (C) 1997-1998 Armin Biere ================|
+--------------------------------------------------------------------------+
| executable       = ./example                                             |
| startup file     = ~/.ccmalloc                                           |
| log file         = stderr                                                |
| start time       = Thu Jan 28 17:12:43 1999                              |
| operating system = Linux 2.0.36 i586 on pitoco.ansp.br                   |
+--------------------------------------------------------------------------+
| only-count        = 0            keep-deallocated-data = 0               |
| check-interval    = 0            check-free-space      = 0               |
| check-start       = 0            file-info             = 1               |
| chain-length      = 0            additional-line       = 1               |
| check-underwrites = 0            print-addresses       = 0               |
| check-overwrites  = 1            print-on-one-line     = 0               |
| sort-by-wasted    = 1            sort-by-size          = 1               |
| # only-log-chain  = 0            continue              = 0               |
| # dont-log-chain  = 0            statistics            = 0               |
| debug             = 0            library-chains        = 0               |
| load-dynlibs      = 1            align-8-byte          = 0               |
`--------------------------------------------------------------------------'

.---------------.
|ccmalloc report|
=======================================================
| total # of|   allocated | deallocated |     garbage |
+-----------+-------------+-------------+-------------+
|      bytes|        3200 |           0 |        3200 |
+-----------+-------------+-------------+-------------+
|allocations|           1 |           0 |           1 |
+-----------------------------------------------------+
| number of checks: 1                                 |
| number of counts: 1                                 |
| retrieving function names for addresses ... done.   |
| reading file info from gdb ... done.                |
| sorting by number of not reclaimed bytes ... done.  |
| number of call chains: 1                            |
| number of ignored call chains: 0                    |
| number of reported call chains: 1                   |
| number of internal call chains: 1                   |
| number of library call chains: 0                    |
=======================================================
|
*100.0% = 3200 Bytes of garbage allocated in 1 allocation
|       |
|       |       0x0804a53a in <main>
|       |
|       |       0x08050e91 in <basic_string<char,
string_char_traits<char>, __default_alloc_template<true, 0>
>::basic_string(char const *)
>
|       |                  at /usr/local/include/g++/std/bastring.h:144
|       |
|       |       0x08050ec2 in <basic_string<char,
string_char_traits<char>, __default_alloc_template<true, 0> >::assign(char
const *)>
|       |                  at /usr/local/include/g++/std/bastring.h:183
|       |
|       |       0x08050eef in <basic_string<char,
string_char_traits<char>, __default_alloc_template<true, 0> >::assign(char
const *, unsig
ned int)>
|       |                  at /usr/local/include/g++/std/bastring.h:181
|       |
|       |       0x08050d2c in <basic_string<char,
string_char_traits<char>, __default_alloc_template<true, 0>
>::replace(unsigned int, unsi
gned int, char const *, unsigned int)>
|       |                  at /usr/local/include/g++/std/bastring.cc:164
|       |
|       |       0x08050a12 in <basic_string<char,
string_char_traits<char>, __default_alloc_template<true, 0>
>::Rep::create(unsigned int)>
|       |                  at /usr/local/include/g++/std/bastring.cc:60
|       |
|       |       0x080509dc in <basic_string<char,
string_char_traits<char>, __default_alloc_template<true, 0>
>::Rep::operator new(unsigned
 int, unsigned int)>
|       |                  at /usr/local/include/g++/std/bastring.cc:33
|       |
|       |       0x08050944 in <__default_alloc_template<true,
0>::allocate(unsigned int)>
|       |                  at /usr/local/include/g++/stl_alloc.h:408
|       |
|       |       0x0805083b in <__default_alloc_template<true,
0>::refill(unsigned int)>
|       |                  at /usr/local/include/g++/stl_alloc.h:516
|       |
|       |       0x080506d5 in <__default_alloc_template<true,
0>::chunk_alloc(unsigned int, int &)>
|       |                  at /usr/local/include/g++/stl_alloc.h:477
|       |
|       `-----> 0x080501d8 in <malloc>
|                          at wrapper.c:325
|        
`------------------------------------------------------

------------
Report of the execution of the program without changing example.cc:

.--------------------------------------------------------------------------.
|================ ccmalloc-0.2.3 (C) 1997-1998 Armin Biere ================|
+--------------------------------------------------------------------------+
| executable       = ./example                                             |
| startup file     = ~/.ccmalloc                                           |
| log file         = stderr                                                |
| start time       = Thu Jan 28 17:13:29 1999                              |
| operating system = Linux 2.0.36 i586 on pitoco.ansp.br                   |
+--------------------------------------------------------------------------+
| only-count        = 0            keep-deallocated-data = 0               |
| check-interval    = 0            check-free-space      = 0               |
| check-start       = 0            file-info             = 1               |
| chain-length      = 0            additional-line       = 1               |
| check-underwrites = 0            print-addresses       = 0               |
| check-overwrites  = 1            print-on-one-line     = 0               |
| sort-by-wasted    = 1            sort-by-size          = 1               |
| # only-log-chain  = 0            continue              = 0               |
| # dont-log-chain  = 0            statistics            = 0               |
| debug             = 0            library-chains        = 0               |
| load-dynlibs      = 1            align-8-byte          = 0               |
`--------------------------------------------------------------------------'

.---------------.
|ccmalloc report|
=======================================================
| total # of|   allocated | deallocated |     garbage |
+-----------+-------------+-------------+-------------+
|      bytes|     1440000 |     1440000 |           0 |
+-----------+-------------+-------------+-------------+
|allocations|       10000 |       10000 |           0 |
+-----------------------------------------------------+
| number of checks: 1                                 |
| number of counts: 20000                             |
| retrieving function names for addresses ... done.   |
| reading file info from gdb ... done.                |
| sorting by number of not reclaimed bytes ... done.  |
| number of call chains: 0                            |
| number of ignored call chains: 0                    |
| number of reported call chains: 0                   |
| number of internal call chains: 0                   |
| number of library call chains: 0                    |
`------------------------------------------------------
--------------

---------------- Makefile (begin) ----------------
CC:=g++
CFLAGS:=-g -Wall
LIBDIR:=/usr/lib
CCMALLOC_LIBS:=$(LIBDIR)/ccmalloc.o -ldl
SOURCE:=example.cc
OBJECT:=$(SOURCE:.cc=.o)
TARGET:=$(SOURCE:.cc=)

all: $(TARGET)

$(TARGET): $(OBJECT)
	$(CC) $^ $(CCMALLOC_LIBS) -o $@

$(OBJECT): $(SOURCE)
	$(CC) $(CFLAGS) -c $^

clean:
	-rm -f *.o $(TARGET)
---------------- Makefile (end) ------------------
---------------- example.cc (begin) ----------------
#include <string>
#include <iostream>
#define SMALL "This is a small string........................"
#define BIG   "This is a big
string................................................................................................."

int main(void)
{
  for (int i = 0; i < 10000; i++) {
    string s = BIG; //  <--------------------HERE
    cout << s << endl;;
  }
  cout.flush();
  return 0;
}
---------------- example.cc (end) ------------------





More information about the Gcc-bugs mailing list