bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Haunting free(): invalid pointer 0x8a11604!


From: Rami Saarinen
Subject: Re: Haunting free(): invalid pointer 0x8a11604!
Date: Fri, 11 Feb 2005 06:51:17 -0800 (PST)

--- Nick Liebmann <address@hidden> wrote:

> I would also suggest declaring empty virtual destructors for any 
> inherited classes for which you have no specific
> need for a destructor. I dont really know why this should be necessary, 
> but for some reason (at least in the past)
> I have found this necessary, and now do it as a habit.
> 
> An isolated test-case is definitly the way to go!

Well I just can't get it any simpler than this. Invalid pointer is still
present exactly like before. Am I missing something? Brains?

I am using cc++ 1.3.1, gcc 3.3.3 20040412, Fedora Core 2 (Linux). cc++ was
compiled on this machine.  

testlistener is the test program.

TCPListener is the one that will create TCPSessionThread per connection
when there are connections pending. 
 
TCPSessionThread does nothing at all (and the invalid pointer error
appears in destructor).

I linked it with -lccgnu2 -ldl  (used also -lpthread, but it is not needed
really). 


Valgrind gives this when connecting the test program and sending some text
to it: 

==4234== Memcheck, a memory error detector for x86-linux.
==4234== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==4234== Using valgrind-2.2.0, a program supervision framework for
x86-linux.
==4234== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==4234== For more details, rerun with: -v
==4234==
==4234== warning: Valgrind's pthread_attr_setinheritsched does nothing
==4234==          your program may misbehave as a result
listener: 153.1.60.204 port: 8001
tcplistener constructor end.
==4234== warning: Valgrind's pthread_attr_setinheritsched does nothing
==4234==          your program may misbehave as a result
new TCPSessionThread
tcpsessionthread run
==4234== warning: Valgrind's pthread_attr_destroy does nothing
==4234==          your program may misbehave as a result
==4234== warning: Valgrind's pthread_cond_destroy is incomplete
==4234==          (it doesn't check if the cond is waited on)
==4234==          your program may misbehave as a result
==4234== Thread 3:
==4234== Invalid read of size 4
==4234==    at 0x1B93C831: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==    by 0x1B93DA0E:
ost::ThreadImpl::ThreadExecHandler(ost::Thread*) (in
/usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==    by 0x1B93C90E: (within /usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==    by 0x1B974847: thread_wrapper (vg_libpthread.c:867)
==4234==  Address 0x1BBBDF48 is 240 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid read of size 4
==4234==    at 0x1B93F188: ost::Semaphore::post() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C84E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==    by 0x1B93DA0E:
ost::ThreadImpl::ThreadExecHandler(ost::Thread*) (in
/usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==    by 0x1B93C90E: (within /usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==  Address 0x1BBBDEF0 is 152 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid read of size 4
==4234==    at 0x1B93F18F: ost::Semaphore::post() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C84E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==    by 0x1B93DA0E:
ost::ThreadImpl::ThreadExecHandler(ost::Thread*) (in
/usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==    by 0x1B93C90E: (within /usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==  Address 0x1BBBDEEC is 148 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid read of size 4
==4234==    at 0x1B93C827: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==    by 0x1B93DA0E:
ost::ThreadImpl::ThreadExecHandler(ost::Thread*) (in
/usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==    by 0x1B93C90E: (within /usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==    by 0x1B974847: thread_wrapper (vg_libpthread.c:867)
==4234==  Address 0x1BBBDEE4 is 140 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid read of size 4
==4234==    at 0x1B93C2D2: ost::Thread::~Thread() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C82E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==    by 0x1B93DA0E:
ost::ThreadImpl::ThreadExecHandler(ost::Thread*) (in
/usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==    by 0x1B93C90E: (within /usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==  Address 0x1BBBDF48 is 240 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid write of size 4
==4234==    at 0x1B93C2EB: ost::Thread::~Thread() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C82E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==    by 0x1B93DA0E:
ost::ThreadImpl::ThreadExecHandler(ost::Thread*) (in
/usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==    by 0x1B93C90E: (within /usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==  Address 0x1BBBDEE4 is 140 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid write of size 4
==4234==    at 0x1B93F023: ost::Semaphore::~Semaphore() (in
/usr/lib/libccgnu2-1
.3.so.0.0.1)
==4234==    by 0x1B93C318: ost::Thread::~Thread() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C82E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==    by 0x1B93DA0E:
ost::ThreadImpl::ThreadExecHandler(ost::Thread*) (in
/usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==  Address 0x1BBBDEE8 is 144 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234== warning: Valgrind's pthread_cond_destroy is incomplete
==4234==          (it doesn't check if the cond is waited on)
==4234==          your program may misbehave as a result
==4234==
==4234== Thread 3:
==4234== Invalid read of size 4
==4234==    at 0x1B975AFB: pthread_mutex_destroy (vg_libpthread.c:1364)
==4234==    by 0x1B93F03A: ost::Semaphore::~Semaphore() (in
/usr/lib/libccgnu2-1
.3.so.0.0.1)
==4234==    by 0x1B93C318: ost::Thread::~Thread() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C82E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==  Address 0x1BBBDEF8 is 160 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid write of size 4
==4234==    at 0x1B975B1A: pthread_mutex_destroy (vg_libpthread.c:1372)
==4234==    by 0x1B93F03A: ost::Semaphore::~Semaphore() (in
/usr/lib/libccgnu2-1
.3.so.0.0.1)
==4234==    by 0x1B93C318: ost::Thread::~Thread() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C82E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==  Address 0x1BBBDEF8 is 160 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid write of size 4
==4234==    at 0x1B975B21: pthread_mutex_destroy (vg_libpthread.c:1373)
==4234==    by 0x1B93F03A: ost::Semaphore::~Semaphore() (in
/usr/lib/libccgnu2-1
.3.so.0.0.1)
==4234==    by 0x1B93C318: ost::Thread::~Thread() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C82E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==  Address 0x1BBBDEFC is 164 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid write of size 4
==4234==    at 0x1B975B28: pthread_mutex_destroy (vg_libpthread.c:1374)
==4234==    by 0x1B93F03A: ost::Semaphore::~Semaphore() (in
/usr/lib/libccgnu2-1
.3.so.0.0.1)
==4234==    by 0x1B93C318: ost::Thread::~Thread() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C82E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==  Address 0x1BBBDF00 is 168 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid free() / delete / delete[]
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x1B93C320: ost::Thread::~Thread() (in
/usr/lib/libccgnu2-1.3.so.
0.0.1)
==4234==    by 0x1B93C82E: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==    by 0x1B93DA0E:
ost::ThreadImpl::ThreadExecHandler(ost::Thread*) (in
/usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==  Address 0x1BBBDEE4 is 140 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234==
==4234== Thread 3:
==4234== Invalid read of size 4
==4234==    at 0x1B93C8B5: (within /usr/lib/libccgnu2-1.3.so.0.0.1)
==4234==    by 0x1B9740D3: thread_exit_wrapper (vg_libpthread.c:710)
==4234==    by 0x1B974857: thread_wrapper (vg_libpthread.c:873)
==4234==    by 0xB000EFE2: do__quit (vg_scheduler.c:1872)
==4234==  Address 0x1BBBDF48 is 240 bytes inside a block of size 412
free'd
==4234==    at 0x1B90313F: operator delete(void*)
(vg_replace_malloc.c:156)
==4234==    by 0x804B191: TCPSessionThread::~TCPSessionThread() (in
/home/rami/s
tuff/garbage/tcptest/testlistener)
==4234==    by 0x804AF81: ost::TCPSession::final() (in
/home/rami/stuff/garbage/
tcptest/testlistener)
==4234==    by 0x1B93C804: ost::Thread::close() (in
/usr/lib/libccgnu2-1.3.so.0.
0.1)
==4234== warning: Valgrind's pthread_attr_setinheritsched does nothing
==4234==          your program may misbehave as a result
new TCPSessionThread
tcpsessionthread run
==4234== warning: Valgrind's pthread_attr_destroy does nothing
==4234==          your program may misbehave as a result
==4234== warning: Valgrind's pthread_cond_destroy is incomplete
==4234==          (it doesn't check if the cond is waited on)
==4234==          your program may misbehave as a result
new TCPSessionThread
tcpsessionthread run
==4234== warning: Valgrind's pthread_attr_destroy does nothing
==4234==          your program may misbehave as a result
new TCPSessionThread
tcpsessionthread run
new TCPSessionThread
tcpsessionthread run
new TCPSessionThread
tcpsessionthread run
==4234==
==4234== ERROR SUMMARY: 84 errors from 13 contexts (suppressed: 33 from 1)
==4234== malloc/free: in use at exit: 6363 bytes in 68 blocks.
==4234== malloc/free: 131 allocs, 69 frees, 28035 bytes allocated.
==4234== For a detailed leak analysis,  rerun with: --leak-check=yes
==4234== For counts of detected errors, rerun with: -v


--
Rami Saarinen


                
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
//XMLString::transcode clean

#ifndef oma__tcplistener_hpp__
#define oma__tcplistener_hpp__

#include <cc++/socket.h>
#include <cc++/thread.h>

#include "TCPSessionThread.cpp"
#include "TransportListener.cpp"

//#ifdef        CCXX_NAMESPACES
using namespace std;
using namespace ost;
//#endif

class TCPListener : public Thread {
public:
  TCPListener(int prt)  {
    InetHostAddress hostaddr=InetHostAddress();
    soc=new TCPSocket(hostaddr,prt);
    cout << "listener: " << hostaddr << " port: " << prt << endl;
    cout << "tcplistener constructor end.\n";
  }
  
  virtual ~TCPListener() {
    if(soc!=NULL)
      delete soc;
  }
  
  virtual void processConnection() {
          TCPSessionThread  *tcp = new TCPSessionThread(*soc);
          tcp->detach();
  }
  
  virtual void run() {
    try {
      while(1) {
            while(soc->isPendingConnection()) {
              processConnection();
        }
      }
    } catch(Socket *socket) {
      cerr << "What's all this then?" << endl;
    }
  }
  
protected:
  TCPSocket *soc;
};

#endif
#ifndef __tcpsessionthread_hpp__
#define __tcpsessionthread_hpp__

#include <string>
#include <iostream>

#include <cc++/thread.h>
#include <cc++/socket.h>

using namespace std;
using namespace ost;

class TCPSessionThread : public TCPSession {
        public:
  TCPSessionThread(TCPSocket &server) : TCPSession(server)  {
    cerr << "new TCPSessionThread\n";
  }
  virtual ~TCPSessionThread() {
  }
  
  virtual void run() {
    cout << "tcpsessionthread run\n";
  }
  
protected:
};


#endif
#include <string>

#include <TCPListener.cpp>
#include <cc++/socket.h>
#include <cc++/thread.h>

using namespace std; 
using namespace ost; 

class TestListener {
public:
  TestListener(): sem(0) {
    listener = new TCPListener(8001);
    listener->start();
  }
  
  ~TestListener() {
    delete listener;
  }

  void run() {
    sem.wait();
  }
  
private:
  Semaphore sem;
  TCPListener *listener;
};



int main() {
  TestListener t; 
  t.run();
  return 0;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]