bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reclaiming memory at dlclose time


From: Bruno Haible
Subject: Re: reclaiming memory at dlclose time
Date: Fri, 15 May 2020 23:37:56 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; )

Jeffrey Walton wrote:
> The use case is incomplete. It does not cover libraries.
> 
> Just ask the OpenJDK guys about libraries like Ncurses and OpenSSL.
> They were discussing library problems on the OpenSSL mailing list in
> the past.
> 
> You see, the application will remain loaded, but Java (and other
> languages like .Net) will load the shared objects multiple times as
> functions are needed (and then unload the shared object when the call
> is done).
> 
> The subsequent accumulated memory leak eventually crashes the app or device.

What you describe here, is a slightly different topic: reclaiming memory
from shared libraries (not programs), at dlclose time (not before exit).

Yes, I confirm that libncurses (libterminfo) has data that it allocates,
like a static initializer would do.

Yes, if a program repeatedly dlopen()s, uses, and dlclose()s such a library,
it will exhibit a memory leak. (Side question: why would anyone dlclose
libncurses or libssl? Sounds wasteful.)

Glibc itself has a number of resource-freeing hooks [1].

GCC allows programmers to mark functions with __attribute__((__destructor__))
[2]. Does glibc walk through these destructors during dlclose()?

Bruno

[1] 
https://sourceware.org/git/?p=glibc.git;a=blob;f=include/libc-symbols.h;hb=HEAD#l245
[2] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html




reply via email to

[Prev in Thread] Current Thread [Next in Thread]