debuginfod-client.c: add dlclose call to prevent resource leak

Message ID 20241101163703.24927-1-ant.v.moryakov@gmail.com
State Rejected
Headers
Series debuginfod-client.c: add dlclose call to prevent resource leak |

Commit Message

Anton Moryakov Nov. 1, 2024, 4:37 p.m. UTC
  Previously, the handle debuginfod_so created by dlopen was not closed 
in all cases, leading to a potential resource leak. This commit adds an 
additional dlclose call to ensure that the handle is always properly 
released, whether the symbols are successfully loaded or not.

Found by RASU JSC.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>

---
 elfutils/libdwfl/debuginfod-client.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Frank Ch. Eigler Nov. 1, 2024, 5:02 p.m. UTC | #1
Hi -

On Fri, Nov 01, 2024 at 07:37:03PM +0300, Anton Moryakov wrote:
> Previously, the handle debuginfod_so created by dlopen was not closed 
> in all cases, leading to a potential resource leak. This commit adds an 
> additional dlclose call to ensure that the handle is always properly 
> released, whether the symbols are successfully loaded or not.
> 
> Found by RASU JSC.
> 
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> --- a/elfutils/libdwfl/debuginfod-client.c
> +++ b/elfutils/libdwfl/debuginfod-client.c
> @@ -127,5 +127,8 @@ __libdwfl_debuginfod_init (void)
>  	  fp_debuginfod_end = NULL;
>  	  dlclose (debuginfod_so);
>  	}
> +	else{
> +      dlclose (debuginfod_so);
> +    }

This code looks broken.  This dlclose's the shared library even in the
successful dlopen/dlsym case, so subsequent calls through the fp_*
function pointers will all fail.

How has this been tested?!

- FChE
  

Patch

diff --git a/elfutils/libdwfl/debuginfod-client.c b/elfutils/libdwfl/debuginfod-client.c
index ee604ad..8f67ecf 100644
--- a/elfutils/libdwfl/debuginfod-client.c
+++ b/elfutils/libdwfl/debuginfod-client.c
@@ -127,5 +127,8 @@  __libdwfl_debuginfod_init (void)
 	  fp_debuginfod_end = NULL;
 	  dlclose (debuginfod_so);
 	}
+	else{
+      dlclose (debuginfod_so);
+    }
     }
 }