Skip to contentSkip to conversation

Fix memory leak in dlm_add_member() when dlm_node_weight() returns less than zero

PATCH In review Jesper Juhl 3 participants 3 messages Jul 18, 2007 – Jul 19, 2007 Distributed lock manager (DLM)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix memory leak in dlm_add_member() when dlm_node_weight() returns less than zero

Greetings,

There's a memory leak in fs/dlm/member.c::dlm_add_member().

If "dlm_node_weight(ls->ls_name, nodeid)" returns < 0, then we'll return without freeing the memory allocated to the (at that point yet unused) 'memb'.
This patch frees the allocated memory in that case and thus avoids the leak.

---

 fs/dlm/member.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
fs/dlm/member.c +3 -1
index 073599d..d099775 100644
@@ -56,8 +56,10 @@ static int dlm_add_member(struct dlm_ls *ls, int nodeid)
 		return -ENOMEM;
 
 	w = dlm_node_weight(ls->ls_name, nodeid);
-	if (w < 0)
+	if (w < 0) {
+		kfree(memb);
 		return w;
+	}
 
 	memb->nodeid = nodeid;
 	memb->weight = w;
maintainer
#1 lore raw
Quoted 9 lines · Jesper Juhl

Greetings,

There's a memory leak in fs/dlm/member.c::dlm_add_member().

If "dlm_node_weight(ls->ls_name, nodeid)" returns < 0, then we'll return without freeing the memory allocated to the (at that point yet unused) 'memb'.
This patch frees the allocated memory in that case and thus avoids the leak.

Yep, thanks.

Dave

#2 lore raw
In reply to Jesper Juhl

Hi,

Now in the GFS2 git tree. Thanks,

Steve.

Quoted 34 lines · Jesper Juhl

Greetings,

There's a memory leak in fs/dlm/member.c::dlm_add_member().

If "dlm_node_weight(ls->ls_name, nodeid)" returns < 0, then we'll return without freeing the memory allocated to the (at that point yet unused) 'memb'.
This patch frees the allocated memory in that case and thus avoids the leak.

---

 fs/dlm/member.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
fs/dlm/member.c +3 -1
index 073599d..d099775 100644
@@ -56,8 +56,10 @@ static int dlm_add_member(struct dlm_ls *ls, int nodeid)
 		return -ENOMEM;
 
 	w = dlm_node_weight(ls->ls_name, nodeid);
-	if (w < 0)
+	if (w < 0) {
+		kfree(memb);
 		return w;
+	}
 
 	memb->nodeid = nodeid;
 	memb->weight = w;