-5

Below shown is the code snippet i am using. Should I allocate space using malloc before doing dlopen?

void* pvHandle = NULL;

/* Dynamically loading library */
pvHandle = dlopen ("libame.so", RTLD_LAZY | RTLD_GLOBAL);       
if (!pvHandle)
    {
        pszError = dlerror();
        cout << "Error : " << pszError;
    }

Please help me clear this doubt. Thanks in Advance.

A R
  • 2,697
  • 3
  • 21
  • 38

1 Answers1

3

No, dlopen returns an opaque handle to the library, you do not need to allocate any memory yourself.

TartanLlama
  • 63,752
  • 13
  • 157
  • 193
  • So what will happen if i am not using dlclose() ? It shouldnt lead to any memory leak. rite? – A R Sep 08 '15 at 12:23
  • You could leak memory, file handles, whatever. You should call `dlclose`. – TartanLlama Sep 08 '15 at 12:27
  • dlclose() leading to segfault on exit. Please check this link : "http://stackoverflow.com/questions/6450828/segmentation-fault-when-using-dlclose-on-android-platform" . I am also facing same issue. As per this link it says we can avoid calling dlclose(). Any other suggestion appreciated. – A R Sep 08 '15 at 12:40
  • @user2599593 If you are encountering platform issues, you can probably get away with omitting the call, so long as you document the issue. – TartanLlama Sep 08 '15 at 12:44