diff mbox series

[2/3] libmultipath: don't leak memory on invalid strings

Message ID 1670974567-8005-3-git-send-email-bmarzins@redhat.com (mailing list archive)
State New, archived
Headers show
Series multipath config fixes | expand

Commit Message

Benjamin Marzinski Dec. 13, 2022, 11:36 p.m. UTC
If set_path() or set_str_noslash() are called with a bad value, they
ignore it and continue to use the old value. But they weren't freeing
the bad value, causing a memory leak.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 libmultipath/dict.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Martin Wilck Dec. 14, 2022, 9:21 a.m. UTC | #1
On Tue, 2022-12-13 at 17:36 -0600, Benjamin Marzinski wrote:
> If set_path() or set_str_noslash() are called with a bad value, they
> ignore it and continue to use the old value. But they weren't freeing
> the bad value, causing a memory leak.
> 
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
diff mbox series

Patch

diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index 97f43387..f4233882 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -130,6 +130,7 @@  set_path(vector strvec, void *ptr, const char *file, int line_nr)
 	if ((*str_ptr)[0] != '/'){
 		condlog(1, "%s line %d, %s is not an absolute path. Ignoring",
 			file, line_nr, *str_ptr);
+		free(*str_ptr);
 		*str_ptr = old_str;
 	} else
 		free(old_str);
@@ -150,6 +151,7 @@  set_str_noslash(vector strvec, void *ptr, const char *file, int line_nr)
 	if (strchr(*str_ptr, '/')) {
 		condlog(1, "%s line %d, %s cannot contain a slash. Ignoring",
 			file, line_nr, *str_ptr);
+		free(*str_ptr);
 		*str_ptr = old_str;
 	} else
 		free(old_str);