Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Memory leak using dlopen and dlclose ?!?

447 views
Skip to first unread message

Jonas Riedel

unread,
Jul 20, 1998, 3:00:00 AM7/20/98
to
Hi,
I am using shared objects in my C-Program with dlopen, dlsym and
dlclose.
Source looks like:

int test()
{

void *pDllHandle;
TDAppl pAppl;

pDllHandle = dlopen(sApplName, RTLD_LAZY);
if(pDllHandle == NULL)
{
...
}
else
{
pAppl =(TDAppl) dlsym( pDllHandle, "fnApplication");
if(pAppl == NULL)
{
...
}
j = pAppl((void *)ACG_message);
dlclose(pDllHandle);
}
}

When i call test in a for/next Loop, the memory of the system
decreases continously.

It seems, that the dlclose does not release the (memory) resources the
shared object uses.

Anyone got any hint ????

Thanks,


J. Riedel


Marcelo Meira

unread,
Jul 20, 1998, 3:00:00 AM7/20/98
to
I don't know much about dl*() functions, but I can say that most
implementations of memory-freeing routines - free() as an example - do
not actually release memory back to the sustem (which means calling
sbrk() w/ a negative value). Rather, they put the freed memory into a
static free-memory list, so this memory will be re-used in the next
memory allocation request. This is usually more efficient that calling
sbrk() for every memory allocation / deallocation request.

I hope this helps,

Marcelo

Usually, memory is only returned to the system when the process exits.

Jonas Riedel wrote:
>
> Hi,
> I am using shared objects in my C-Program with dlopen, dlsym and
> dlclose.
> Source looks like:
>
> int test()
> {

...


> }
>
> When i call test in a for/next Loop, the memory of the system
> decreases continously.
>
> It seems, that the dlclose does not release the (memory) resources the
> shared object uses.
>
> Anyone got any hint ????
>
> Thanks,
>
> J. Riedel

--

----------------
Marcelo L. Meira, Programmer
spam bait: postmaster@localhost
e-mail: marcelo.meira at waii dot com
Western Geophysical - (713) 689-2679

"UNIX _IS_ user friendly; it's just picky about who its friends are."

Ken Pizzini

unread,
Jul 21, 1998, 3:00:00 AM7/21/98
to
On Mon, 20 Jul 1998 15:12:41 GMT, Jonas Riedel <rie...@4com.de> wrote:
> pDllHandle = dlopen(sApplName, RTLD_LAZY);
...

> pAppl =(TDAppl) dlsym( pDllHandle, "fnApplication");
...
> }
> j = pAppl((void *)ACG_message);
> dlclose(pDllHandle);

>When i call test in a for/next Loop, the memory of the system


>decreases continously.
>
>It seems, that the dlclose does not release the (memory) resources the
>shared object uses.

Three possibilities come to mind:
* pAppl() malloc()s some memory which you are failing to free()
(directly or via a pApplFree()-like call)
* the library initializes some private data structure which
is not being released in the dlclose()
* the dl*() functions themselves are buggy WRT memory leaks

--Ken Pizzini

0 new messages