Skip to contentSkip to conversation

dlm: fixed memory leaks after failed ls_remove_names allocation

PATCH Superseded Vasily Averin 1 participant 2 messages Nov 15, 2018 Distributed lock manager (DLM)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dlm: fixed memory leaks after failed ls_remove_names allocation

If allocation fails on last elements of array need to free already allocated elements.

Fixes 789924ba635f ("dlm: fix race between remove and lookup")
Cc: stable at kernel.org # 3.6

---
 fs/dlm/lockspace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/dlm/lockspace.c +2 -1
index 5ba94be006ee..f99e110a0af8 100644
@@ -532,7 +532,7 @@ static int new_lockspace(const char *name, const char *cluster,
 		ls->ls_remove_names[i] = kzalloc(DLM_RESNAME_MAXLEN+1,
 						 GFP_KERNEL);
 		if (!ls->ls_remove_names[i])
-			goto out_rsbtbl;
+			goto out_remove_names;
 	}
 
 	idr_init(&ls->ls_lkbidr);
@@ -680,6 +680,7 @@ static int new_lockspace(const char *name, const char *cluster,
 	kfree(ls->ls_recover_buf);
  out_lkbidr:
 	idr_destroy(&ls->ls_lkbidr);
+ out_remove_names:
 	for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) {
 		if (ls->ls_remove_names[i])
 			kfree(ls->ls_remove_names[i]);
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 dlm: fixed memory leaks after failed ls_remove_names allocation

If allocation fails on last elements of array need to free already allocated elements.

v2: just move existing out_rsbtbl label to right place

Fixes 789924ba635f ("dlm: fix race between remove and lookup")
Cc: stable at kernel.org # 3.6

---
 fs/dlm/lockspace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dlm/lockspace.c +1 -1
index 5ba94be006ee..6a1529e478f3 100644
@@ -680,11 +680,11 @@ static int new_lockspace(const char *name, const char *cluster,
 	kfree(ls->ls_recover_buf);
  out_lkbidr:
 	idr_destroy(&ls->ls_lkbidr);
+ out_rsbtbl:
 	for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) {
 		if (ls->ls_remove_names[i])
 			kfree(ls->ls_remove_names[i]);
 	}
- out_rsbtbl:
 	vfree(ls->ls_rsbtbl);
  out_lsfree:
 	if (do_unreg)
Signature · 1 line
2.17.1