LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-02-2011, 02:21 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,732
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Understanding Segmentation fault in Qt project through GDB


I ve added the following to the .pro file, if that matters:
Code:
QMAKE_CXXFLAGS_DEBUG *= -pg
QMAKE_LFLAGS_DEBUG *= -pg
I need to understand where to look when I get the following through GDB:
The print statement shown in Green gets printed and then I receive the SEG fault, I don't know where the control goes then? Any hints?
Code:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff2338910 (LWP 17107)]
QHostAddressPrivate::clear (this=0x0) at /var/tmp/qt-src/src/network/kernel/qhostaddress.cpp:292
292     /var/tmp/qt-src/src/network/kernel/qhostaddress.cpp: No such file or directory.
        in /var/tmp/qt-src/src/network/kernel/qhostaddress.cpp
Relevant code:
This is a client server program. When the client gets closed, this gets called:
Code:
connect (objTcpSocketUtility->objTcpSocket, SIGNAL (error(QAbstractSocket::SocketError)), this, SLOT (socketError (QAbstractSocket::SocketError)), Qt::DirectConnection);
socketError calls closeConnection
Code:
closeConnection()
{
   objTcpSocketUtility->destroy_Socket ();
   printf ("\n==========I think=====================\n");
}
and the destroy_Socket contains this:
Code:
void destroy_Socket()
{
   objTcpSocket->close ();
   delete objTcpSocket;

   objTcpSocket = NULL; 
}

Last edited by Aquarius_Girl; 02-02-2011 at 03:16 AM.
 
Old 02-02-2011, 05:36 AM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,732

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
SOLVED:

Now I realize I didn't mention that I had stored that socket pointer in a vector (shallow copy) so when the destroy_socket function deleteed the socket, the shallow copy in the vector became a dangling pointer and thus resulted in a SEG fault!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
segmentation fault while porting project c,c++,fortran files from windows to linux varsha Linux - Software 1 02-02-2011 02:54 AM
Segmentation Fault and GDB McCoder Programming 1 07-23-2010 02:30 PM
gftp Segmentation fault need help with gdb j0hn-d0e Linux - Software 4 11-05-2009 02:14 AM
gdb segmentation fault i.you Linux - Software 1 04-11-2007 04:25 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration