diff mbox series

eal: fix leak in shared lib mode detection

Message ID 20210506100637.23645-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series eal: fix leak in shared lib mode detection | expand

Checks

Context Check Description
ci/intel-Testing success Testing PASS
ci/Intel-compilation fail Compilation issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot success github build: passed
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/checkpatch success coding style OK

Commit Message

David Marchand May 6, 2021, 10:06 a.m. UTC
This is reported by our internal covscan:

1. dpdk-20.11/lib/librte_eal/common/eal_common_options.c:508: alloc_fn:
Storage is returned from allocation function "dlopen".
6. dpdk-20.11/lib/librte_eal/common/eal_common_options.c:508:
leaked_storage: Failing to save or free storage allocated by
"dlopen("librte_eal.so.21.0", 5)" leaks it.

 #   506|   	 * shared library is not already loaded i.e. it's
 #   statically linked.)
 #   507|   	 */
 #   508|-> 	if (dlopen("librte_eal.so."ABI_VERSION, RTLD_LAZY |
 #   RTLD_NOLOAD) != NULL &&
 #   509|   			*default_solib_dir != '\0' &&
 #   510|   			stat(default_solib_dir, &sb) == 0 &&

This leak is not an issue per se, but on the other hand, this is easy
to fix and I prefer not having to waive this warning later.

Fixes: 06c7871dde01 ("eal: restrict default plugin path to shared lib mode")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_options.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Bruce Richardson May 6, 2021, 10:40 a.m. UTC | #1
On Thu, May 06, 2021 at 12:06:37PM +0200, David Marchand wrote:
> This is reported by our internal covscan:
> 
> 1. dpdk-20.11/lib/librte_eal/common/eal_common_options.c:508: alloc_fn:
> Storage is returned from allocation function "dlopen".
> 6. dpdk-20.11/lib/librte_eal/common/eal_common_options.c:508:
> leaked_storage: Failing to save or free storage allocated by
> "dlopen("librte_eal.so.21.0", 5)" leaks it.
> 
>  #   506|   	 * shared library is not already loaded i.e. it's
>  #   statically linked.)
>  #   507|   	 */
>  #   508|-> 	if (dlopen("librte_eal.so."ABI_VERSION, RTLD_LAZY |
>  #   RTLD_NOLOAD) != NULL &&
>  #   509|   			*default_solib_dir != '\0' &&
>  #   510|   			stat(default_solib_dir, &sb) == 0 &&
> 
> This leak is not an issue per se, but on the other hand, this is easy
> to fix and I prefer not having to waive this warning later.
> 
> Fixes: 06c7871dde01 ("eal: restrict default plugin path to shared lib mode")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  lib/eal/common/eal_common_options.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
> index 97ab6e00fd..ff5861b5f3 100644
> --- a/lib/eal/common/eal_common_options.c
> +++ b/lib/eal/common/eal_common_options.c
> @@ -509,10 +509,14 @@ is_shared_build(void)
>  	}
>  
>  	while (len >= minlen) {
> +		void *handle;
> +
>  		/* check if we have this .so loaded, if so - shared build */
>  		RTE_LOG(DEBUG, EAL, "Checking presence of .so '%s'\n", soname);
> -		if (dlopen(soname, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
> +		handle = dlopen(soname, RTLD_LAZY | RTLD_NOLOAD);
> +		if (handle != NULL) {
>  			RTE_LOG(INFO, EAL, "Detected shared linkage of DPDK\n");
> +			dlclose(handle);
>  			return 1;
>  		}
>  

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Since this is not really a leak, I'm not sure it needs backport, but no
harm in CC'ing stable and letting maintainers choose.
Thomas Monjalon May 10, 2021, 1:18 p.m. UTC | #2
06/05/2021 12:40, Bruce Richardson:
> On Thu, May 06, 2021 at 12:06:37PM +0200, David Marchand wrote:
> > This is reported by our internal covscan:
> > 
> > 1. dpdk-20.11/lib/librte_eal/common/eal_common_options.c:508: alloc_fn:
> > Storage is returned from allocation function "dlopen".
> > 6. dpdk-20.11/lib/librte_eal/common/eal_common_options.c:508:
> > leaked_storage: Failing to save or free storage allocated by
> > "dlopen("librte_eal.so.21.0", 5)" leaks it.
> > 
> >  #   506|   	 * shared library is not already loaded i.e. it's
> >  #   statically linked.)
> >  #   507|   	 */
> >  #   508|-> 	if (dlopen("librte_eal.so."ABI_VERSION, RTLD_LAZY |
> >  #   RTLD_NOLOAD) != NULL &&
> >  #   509|   			*default_solib_dir != '\0' &&
> >  #   510|   			stat(default_solib_dir, &sb) == 0 &&
> > 
> > This leak is not an issue per se, but on the other hand, this is easy
> > to fix and I prefer not having to waive this warning later.
> > 
> > Fixes: 06c7871dde01 ("eal: restrict default plugin path to shared lib mode")
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks
diff mbox series

Patch

diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
index 97ab6e00fd..ff5861b5f3 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -509,10 +509,14 @@  is_shared_build(void)
 	}
 
 	while (len >= minlen) {
+		void *handle;
+
 		/* check if we have this .so loaded, if so - shared build */
 		RTE_LOG(DEBUG, EAL, "Checking presence of .so '%s'\n", soname);
-		if (dlopen(soname, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
+		handle = dlopen(soname, RTLD_LAZY | RTLD_NOLOAD);
+		if (handle != NULL) {
 			RTE_LOG(INFO, EAL, "Detected shared linkage of DPDK\n");
+			dlclose(handle);
 			return 1;
 		}