Fix potential handle leak by ensuring dlclose is always called on debuginfod_so

Message ID 20241101184936.48267-1-ant.v.moryakov@gmail.com
State Rejected
Headers
Series Fix potential handle leak by ensuring dlclose is always called on debuginfod_so |

Commit Message

Anton Moryakov Nov. 1, 2024, 6:49 p.m. UTC
  first report
HANDLE_LEAK.EX The handle 'debuginfod_so' is created at debuginfod-client.c:104 by calling function 'dlopen' and lost at debuginfod-client.c:129.

second report
HANDLE_LEAK.EX The handle 'debuginfod_so' is created at debuginfod-client.c:107 by calling function 'dlopen' and lost at debuginfod-client.c:129.

In __libdwfl_debuginfod_init, added dlclose(debuginfod_so) after symbol loading,
ensuring that the handle is released whether symbols are successfully loaded or not.
This prevents potential handle leak reported by static analysis.

Found by RASU JSC.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>

---
 elfutils/libdwfl/debuginfod-client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

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

> first report
> HANDLE_LEAK.EX The handle 'debuginfod_so' is created at debuginfod-client.c:104 by calling function 'dlopen' and lost at debuginfod-client.c:129.
> second report
> HANDLE_LEAK.EX The handle 'debuginfod_so' is created at debuginfod-client.c:107 by calling function 'dlopen' and lost at debuginfod-client.c:129.
> [...]
> This prevents potential handle leak reported by static analysis.
> 
> Found by RASU JSC.
> 
> Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>

NO.  The shared library handle is held deliberately, so that
subsequent dlsym'd function calls can work.  Please stop sending junk
patches.

- FChE
  

Patch

diff --git a/elfutils/libdwfl/debuginfod-client.c b/elfutils/libdwfl/debuginfod-client.c
index ee604ad..b29c455 100644
--- a/elfutils/libdwfl/debuginfod-client.c
+++ b/elfutils/libdwfl/debuginfod-client.c
@@ -125,7 +125,7 @@  __libdwfl_debuginfod_init (void)
 	  fp_debuginfod_find_executable = NULL;
 	  fp_debuginfod_find_debuginfo = NULL;
 	  fp_debuginfod_end = NULL;
-	  dlclose (debuginfod_so);
 	}
+	dlclose (debuginfod_so);
     }
 }