[lustre-devel] [PATCH 21/24] lnet: Memory leak on adding existing interface

James Simmons jsimmons at infradead.org
Mon Sep 5 18:55:34 PDT 2022


From: Frank Sehr <fsehr at whamcloud.com>

In the function lnet_dyn_add_ni an lnet_ni structure is allocated.
In case of an error the function returns without freeing the memory of
the structure.
Added handling of possible lnet_net structure memory leaks.

WC-bug-id: https://jira.whamcloud.com/browse/LU-16081
Lustre-commit: 26beb8664f4533a6e ("LU-16081 lnet: Memory leak on adding existing interface")
Signed-off-by: Frank Sehr <fsehr at whamcloud.com>
Reviewed-on: https://review.whamcloud.com/48173
Reviewed-by: Chris Horn <chris.horn at hpe.com>
Reviewed-by: Serguei Smirnov <ssmirnov at whamcloud.com>
Reviewed-by: James Simmons <jsimmons at infradead.org>
Reviewed-by: Oleg Drokin <green at whamcloud.com>
Signed-off-by: James Simmons <jsimmons at infradead.org>
---
 net/lnet/lnet/api-ni.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/net/lnet/lnet/api-ni.c b/net/lnet/lnet/api-ni.c
index 0449136..9bf2860 100644
--- a/net/lnet/lnet/api-ni.c
+++ b/net/lnet/lnet/api-ni.c
@@ -3551,25 +3551,34 @@ int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf)
 		return -ENOMEM;
 
 	for (i = 0; i < conf->lic_ncpts; i++) {
-		if (conf->lic_cpts[i] >= LNET_CPT_NUMBER)
+		if (conf->lic_cpts[i] >= LNET_CPT_NUMBER) {
+			lnet_net_free(net);
 			return -EINVAL;
+		}
 	}
 
 	ni = lnet_ni_alloc_w_cpt_array(net, conf->lic_cpts, conf->lic_ncpts,
 				       conf->lic_ni_intf);
-	if (!ni)
+	if (!ni) {
+		lnet_net_free(net);
 		return -ENOMEM;
+	}
 
 	lnet_set_tune_defaults(tun);
 
 	mutex_lock(&the_lnet.ln_api_mutex);
-	if (the_lnet.ln_state != LNET_STATE_RUNNING)
+	if (the_lnet.ln_state != LNET_STATE_RUNNING) {
+		lnet_net_free(net);
 		rc = -ESHUTDOWN;
-	else
+	} else {
 		rc = lnet_add_net_common(net, tun);
+	}
 
 	mutex_unlock(&the_lnet.ln_api_mutex);
 
+	if (rc)
+		lnet_ni_free(ni);
+
 	return rc;
 }
 
-- 
1.8.3.1



More information about the lustre-devel mailing list