[PATCH] Fix memory leak in dlopen()/dlclose().
Joakim Tjernlund
joakim.tjernlund at transmode.se
Thu Feb 10 07:02:11 UTC 2011
> From: Philip Craig <philipjcraig at gmail.com>
> To: uclibc at uclibc.org
> Date: 2011/02/08 07:23
> Subject: [PATCH] Fix memory leak in dlopen()/dlclose().
> Sent by: uclibc-bounces at uclibc.org
>
> The linked list of library dependencies created by dlopen() was not
> being freed by dlclose().
>
> Signed-off-by: Philip Craig <philipjcraig at gmail.com>
> ---
> Tested with uClibc 0.9.29 only.
> Code inspection shows the error is still present in latest git,
> I compile tested there.
>
> ldso/libdl/libdl.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c
> index b88bc48..ee5cd44 100644
> --- a/ldso/libdl/libdl.c
> +++ b/ldso/libdl/libdl.c
> @@ -922,6 +922,10 @@ static int do_dlclose(void *vhandle, int need_fini)
> free(tpnt);
> }
> }
> + for (rpnt1 = handle->next; rpnt1; rpnt1 = rpnt1_tmp) {
> + rpnt1_tmp = rpnt1->next;
> + free(rpnt1);
> + }
> free(handle->init_fini.init_fini);
> free(handle);
This looks good to me too. Could probably be simplified a little though:
free(handle->init_fini.init_fini);
+ for (rpnt1 = handle; rpnt1; rpnt1 = rpnt1_tmp) {
+ rpnt1_tmp = rpnt1->next;
+ free(rpnt1);
+ }
- free(handle);
Jocke
More information about the uClibc
mailing list