LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-19-2008, 01:45 AM   #1
odedbobi
LQ Newbie
 
Registered: Nov 2008
Posts: 1

Rep: Reputation: 0
Smile Segmentation fault problem


hello people.
i have a problem with my .so .
i am dynamically loading and unloading my libtemp.so using the dlopen and dlclose functions.
my .so contains many global instances of many classes.
i can see that all my global constructors are called on load and all my destructors are called on unload.
everything seems fine.
but when my program ends, i get a segmentation fault error.
here is my main.cpp:

int main( int argc, char * argv[] )
{
if( argc != 2 ){
printf("usage [so name] \n");
return 0;
}
printf("Before Load\r\n");
void* pHandle = dlopen(argv[1]);
if( pHandle == NULL ){
printf("%s\r\n", dlerror());
}else{
printf("Load: Went fine\r\n");
if( dlclose(pHandle) ){
printf("UnLoad Went Ok\r\n");
}else{
printf("UnLoad Failed\r\n");
}
}
return 0;
}

the output will be:
Before Load
Load: Went fine
UnLoad Went Ok
Segmentation fault

when debugging, i can see that my main reached it's ending, but still i get the segmentation fault error.
what might caused the problem ?
is it some memory leak ?
one of my globals problems ?
i will appreciate any help, cause i am kind of lost here.
thanks
 
Old 11-20-2008, 12:03 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
I would expect the traceback and/or registers and/or stack contents at the point of the segmentation fault would give you a good hint about which cleanup code is failing.

If the crash is low enough in memory deallocation, then something overwrote memory that didn't belong to it, and you should be able to identify the clobbered address and rerun trapping all writes to that address.

If the crash is a call to a destructor that was located in the .so, that should be pretty obvious. I've hit many situations in Windows where an object is owned by some class static in the .exe but needs a destructor in the .dll, so the only way to avoid the crash at the end is never unload the .dll. I don't think I've seen that in Linux. I think the templated library I/O code that tends to cause such issues was coded more carefully to avoid questionable class statics in Linux than in Windows.

But anyway, once you find a call to unloaded code, it should be pretty easy to backtrack to the cause.
 
  


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 - memory problem? felipebil Programming 10 11-19-2008 10:01 PM
Regex.h problem in c++, segmentation fault vargadanis Programming 4 07-14-2008 05:36 PM
Problem with Segmentation Fault in Linux akzare Programming 2 08-16-2006 11:42 PM
problem with segmentation fault lucs Slackware 2 04-28-2005 09:14 AM
Segmentation Fault Problem luvonmik Linux - Newbie 2 02-14-2004 07:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:26 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