C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-19-2008, 02:07 AM   #1
Registered User
 
Join Date: Nov 2008
Posts: 1
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:
Code:
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
odedbobi is offline   Reply With Quote
Old 11-19-2008, 03:36 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
You are supposed to pass two parameters to dlopen - not doing so could cause all sorts of different problems.

Also, your destructors are called on dlclose(), so you if you are accessing memory that isn't valid from the destructors, it will cause a seg fault.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault ith g_type_check_class_cast () from /usr/lib/libgobject-2.0.so.0 lehe Game Programming 7 02-02-2009 07:27 AM
Strange segmentation fault Ron C Programming 24 06-15-2008 02:10 PM
Segmentation Fault hmm? pobri19 C Programming 4 05-03-2008 07:51 AM
Re: Segmentation fault turkish_van C Programming 8 01-20-2007 05:50 PM
[C++] Segmentation Fault {Novice C++ Programmer} INFERNO2K C++ Programming 24 06-08-2005 07:44 PM


All times are GMT -6. The time now is 04:00 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22