Segmentation fault problem

This is a discussion on Segmentation fault problem within the Linux Programming forums, part of the Platform Specific Boards category; hello people. i have a problem with my .so . i am dynamically loading and unloading my libtemp.so using the ...

  1. #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

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Strange segmentation fault
    By Ron in forum C Programming
    Replies: 24
    Last Post: 06-15-2008, 03:10 PM
  3. Segmentation Fault hmm?
    By pobri19 in forum C Programming
    Replies: 4
    Last Post: 05-03-2008, 08:51 AM
  4. Re: Segmentation fault
    By turkish_van in forum C Programming
    Replies: 8
    Last Post: 01-20-2007, 05:50 PM
  5. [C++] Segmentation Fault {Novice C++ Programmer}
    By INFERNO2K in forum C++ Programming
    Replies: 24
    Last Post: 06-08-2005, 08:44 PM

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