Skip to contentSkip to conversation

libmultipath: fix a memory leak in disassemble_status func

PATCH Superseded Zhiqiang Liu 3 participants 4 messages Jul 28, 2020 – Aug 6, 2020 Device mapper

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libmultipath: fix a memory leak in disassemble_status func

In disassemble_status func, for dealing with selector args, word is allocated by get_word func. However, word is not freed. Then a memory leak occurs.

Here, we call FREE(word) to free word.

---
 libmultipath/dmparser.c | 1 +
 1 file changed, 1 insertion(+)
libmultipath/dmparser.c +1 -0
index 3dc77242..a4a989b2 100644
@@ -584,6 +584,7 @@ int disassemble_status(char *params, struct multipath *mpp)
 						   &def_minio) == 1 &&
 					    def_minio != mpp->minio)
 							mpp->minio = def_minio;
+					FREE(word);
 				} else
 					p += get_word(p, NULL);
 			}
Signature · 1 line
2.24.0.windows.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Zhiqiang Liu

In disassemble_status func, for dealing with selector args, word is allocated by get_word func. However, word is not freed. Then a memory leak occurs.

Here, we call FREE(word) to free word.

Err... At the risk of sounding stupid, There is a least-pending selector? Hannes, you added this code (commit 35ad40b4 "leastpending IO loadbalancing is not displayed properly"). Was this a Suse thing? Is it still a Suse thing, or have queue-length and service-time replaced it?

At any rate, for the patch itself (assuming that the correct answer isn't to just delete the least-pending code),

Quoted 21 lines
---
 libmultipath/dmparser.c | 1 +
 1 file changed, 1 insertion(+)
libmultipath/dmparser.c +1 -0
index 3dc77242..a4a989b2 100644
@@ -584,6 +584,7 @@ int disassemble_status(char *params, struct multipath *mpp)
 						   &def_minio) == 1 &&
 					    def_minio != mpp->minio)
 							mpp->minio = def_minio;
+					FREE(word);
 				} else
 					p += get_word(p, NULL);
 			}
Signature · 1 line
2.24.0.windows.2
#2 lore raw
Quoted 6 lines · Benjamin Marzinski
Quoted 5 lines · Zhiqiang Liu

In disassemble_status func, for dealing with selector args, word is allocated by get_word func. However, word is not freed. Then a memory leak occurs.

Quoted 7 lines
Quoted 1 line

Here, we call FREE(word) to free word.

Err... At the risk of sounding stupid, There is a least-pending selector? Hannes, you added this code (commit 35ad40b4 "leastpending IO loadbalancing is not displayed properly"). Was this a Suse thing? Is it still a Suse thing, or have queue-length and service-time replaced it?

Thanks for your reply.
I am sorry that I cannot answer these questions. I found the memory leak through code review.
In addition, I forget to add a check of whether work is null. I will send the v2 patch.

Quoted 30 lines

At any rate, for the patch itself (assuming that the correct answer isn't to just delete the least-pending code),

Quoted 21 lines
---
 libmultipath/dmparser.c | 1 +
 1 file changed, 1 insertion(+)
libmultipath/dmparser.c +1 -0
index 3dc77242..a4a989b2 100644
@@ -584,6 +584,7 @@ int disassemble_status(char *params, struct multipath *mpp)
 						   &def_minio) == 1 &&
 					    def_minio != mpp->minio)
 							mpp->minio = def_minio;
+					FREE(word);
 				} else
 					p += get_word(p, NULL);
 			}
Signature · 1 line
2.24.0.windows.2

.

#3 lore raw
In reply to Benjamin Marzinski

Hi Ben,

Quoted 7 lines · Benjamin Marzinski
Quoted 5 lines · Zhiqiang Liu

In disassemble_status func, for dealing with selector args, word is allocated by get_word func. However, word is not freed. Then a memory leak occurs.

Here, we call FREE(word) to free word.

Quoted 7 lines

Err... At the risk of sounding stupid, There is a least-pending selector? Hannes, you added this code (commit 35ad40b4 "leastpending IO
loadbalancing is not displayed properly"). Was this a Suse thing? Is it
still a Suse thing, or have queue-length and service-time replaced it?

Yes, it's a "SUSE thing" (originally developed by HP). SLE15 still supports it; I don't know if it's actually used.
It was discussed here last year, see:
https://patchwork.kernel.org/patch/10878905/

Regards,
Martin