core dump in std::list push_back

J

Jaydeep Chovatia

Hi,

I am getting core dump while using push_back of std::list. What could
be the reason for this?
std::list is of type: std::list<MyClient*>

#0 0x0000003f9b063803 in
std::_List_node_base::hook(std::_List_node_base*) () from /usr/lib64/
libstdc++.so.6
#1 0x00000000007ad596 in std::list<::MyClient*,
std::allocator<::MyClient*> >::_M_insert (
this=0x1e19780, __position=, __x=@0x7fdbbbdbdd38)
at /home/linux/rhes4_x64/bin/../lib/gcc/x86_64-unknown-linux-gnu/
4.1.2/../../../../include/c++/4.1.2/bits/stl_list.h:1140
#2 0x00000000007ad5c1 in std::list<::MyClient*,
std::allocator<::MyClient*> >::push_back (
this=0x1e19780, __x=@0x7fdbbbdbdd38)
at /home/linux/rhes4_x64/bin/../lib/gcc/x86_64-unknown-linux-gnu/
4.1.2/../../../../include/c++/4.1.2/bits/stl_list.h:761
#3 0x00000000007ac356 in ::MyClientObjPool::addNewObject
(this=0x1e19678)
at objpool/MyClientObjPool.cxx:254
#4 0x00000000007ac744 in ::MyClientObjPool::checkUpdate
(this=0x1e19678)
at objpool/MyClientObjPool.cxx:175
#5 0x00000000007ac82d in careTakerThreadMain (p=0x1e19678) at objpool/
MyClientObjPool.cxx:28
#6 0x0000003f978077e1 in start_thread () from /lib64/libpthread.so.0
#7 0x0000003f974e153d in clone () from /lib64/libc.so.6

Thank you,
Jaydeep
 
V

Victor Bazarov

I am getting core dump while using push_back of std::list. What could
be the reason for this?
std::list is of type: std::list<MyClient*>

There is a logic error on line 42 of your program. At least that's what
my crystal ball says.

V
 
J

Jaydeep Chovatia

There is a logic error on line 42 of your program.  At least that's what
my crystal ball says.

V

Hi Victor,

Thanks for your response.
Sorry, I didn't get what is the logic error in code. Can you please
elaborate little bit more?

Thank you,
Jaydeep
 
V

Victor Bazarov

Hi Victor,

Thanks for your response.
Sorry, I didn't get what is the logic error in code. Can you please
elaborate little bit more?

A logic error is not a syntax error. Most likely to manifest itself as
a run-time malfunction. Sometimes it's relatively harmless (like
outputting 'a' when 'b' should be output), sometimes it leads to crash
(access to memory that doesn't belong to the process, for instance).

My crystal ball is clouding up; I'm afraid I can't help you any further
without additional information about your program. See FAQ 5.8.

V
 
D

Drew Lawson

Hi,

I am getting core dump while using push_back of std::list. What could
be the reason for this?
std::list is of type: std::list<MyClient*>

Without the code, it will be pretty hard to even guess.

However, I'll take a "frequently burned" guess. The last two frames
in your stack trace are in std::allocator. In my experience, there
are only two reasons for a production memory allocator to crash.

One is that your program is using up all available memory. That's
(in my experiece) the less common reason.

The most common reason is that something, before the allocation was
started, corrupted the memory that the allocator is using.

Look at your pointer/new/delete usage. I'd bet that you use a
pointer somewhere after you deleted the object that it pointed to.
 
A

Angus

Without the code, it will be pretty hard to even guess.

However, I'll take a "frequently burned" guess.  The last two frames
in your stack trace are in std::allocator.  In my experience, there
are only two reasons for a production memory allocator to crash.

One is that your program is using up all available memory.  That's
(in my experiece) the less common reason.

The most common reason is that something, before the allocation was
started, corrupted the memory that the allocator is using.

Look at your pointer/new/delete usage.  I'd bet that you use a
pointer somewhere after you deleted the object that it pointed to.











--
Drew Lawson            |  Savage bed foot-warmer
                       |    of purest feline ancestry
                       |  Look out little furryfolk
                       |    it's the all-night working cat

If the pointers in the list are new'd then you need to call delete on
the object BEFORE erasing the object in the list. This is a common
mistake. It is one of the not to do items in Effective C++.

But without seeing other bits of your code this is pure speculation.
 
N

Noah Roberts

Hi Victor,

Thanks for your response.
Sorry, I didn't get what is the logic error in code. Can you please
elaborate little bit more?

The operand you're supplying to the towel operator is a dead babelfish.
This always results in undefined behavior, usually manifested as the
absurd.
 
J

Jaydeep Chovatia

If the pointers in the list are new'd then you need to call delete on
the object BEFORE erasing the object in the list.  This is a common
mistake.  It is one of the not to do items in Effective C++.

But without seeing other bits of your code this is pure speculation.

Hi Drew,

I am calling delete on object after erasing from the list. Do you
thing this might have triggered core dump?

Thank you,
Jaydeep
 
A

Angus

On Mar 24, 8:24 pm, (e-mail address removed) (Drew Lawson) wrote:
Hi Drew,

I am calling delete on object after erasing from the list. Do you
thing this might have triggered core dump?

Thank you,
Jaydeep

I thought that was a good guess.

If you have erased the element in the container then what are you
deleting?

A few points:
1. Definitely delete before erase.
2. If possible use a smart pointer. That way you don't have to worry
about managing the lifetime of the pointer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top