multipath-tools tests: fix memory leak in alias test
PATCH 1/5 multipath-tools tests: fix memory leak in alias test
From: Martin Wilck <[email protected]>
--- tests/alias.c | 2 ++ 1 file changed, 2 insertions(+)
tests/alias.c +2 -0
@@ -652,6 +652,7 @@ static void al_a(void **state) alias =allocate_binding (0 ,"WWIDa" ,1 ,"MPATH" );assert_ptr_not_equal (alias,NULL );assert_string_equal (alias,"MPATHa" ); +free (alias); }static void al_zz (void **state)
@@ -668,6 +669,7 @@ static void al_zz(void **state) alias =allocate_binding (0 ,"WWIDzz" ,26 *26 +26 ,"MPATH" );assert_ptr_not_equal (alias,NULL );assert_string_equal (alias,"MPATHzz" ); +free (alias); }static void al_0 (void **state)
Signature · 1 line
2.28.0
PATCH 2/5 libmultipath: fix memory leak in ble handlers
From: Martin Wilck <[email protected]>
Since patch "libmultipath fix a memory leak in set_ble_device", strings are strdup'd in set_ble_device() and store_ble(). The passed string must therefore be freed in the handlers in dict.c.
--- libmultipath/dict.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
libmultipath/dict.c +9 -3
@@ -1499,7 +1499,8 @@ blacklist_exceptions_handler(struct config *conf, vector strvec)static int \ ble_ ## option ## _handler (struct config *conf, vector strvec) \ { \ -char * buff; \ +char *buff; \ +int rc; \ \if (!conf->option) \return 1 ; \
@@ -1508,7 +1509,9 @@ ble_ ## option ## _handler (struct config *conf, vector strvec) \if (!buff) \return 1 ; \ \ -return store_ble (conf->option, buff,ORIGIN_CONFIG ); \ + rc =store_ble (conf->option, buff,ORIGIN_CONFIG ); \ +free (buff); \ +return rc; \ }#define declare_ble_device_handler (name, option, vend, prod) \
@@ -1516,6 +1519,7 @@ static int \ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \ { \ char * buff; \ + int rc; \ \ if (!conf->option) \ return 1; \
@@ -1524,7 +1528,9 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \if (!buff) \return 1 ; \ \ -return set_ble_device (conf->option, vend, prod,ORIGIN_CONFIG ); \ + rc =set_ble_device (conf->option, vend, prod,ORIGIN_CONFIG ); \ +free (buff); \ +return rc; \ }declare_ble_handler (blist_devnode)
Signature · 1 line
2.28.0
PATCH 3/5 libmultipath: fix enable_foreign memory leak
In reply to [email protected]From: Martin Wilck <[email protected]>
enable_foreign wasn't freed in free_config(). Do it, and make sure it's always a malloc'd string.
--- libmultipath/config.c | 2 ++ multipath/main.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
libmultipath/config.c +2 -0
@@ -631,6 +631,8 @@ free_config (struct config * conf)if (conf->config_dir)FREE (conf->config_dir); +if (conf->enable_foreign) +FREE (conf->enable_foreign);free_blacklist (conf->blist_devnode);free_blacklist (conf->blist_wwid);
multipath/main.c +1 -1
@@ -997,7 +997,7 @@ main (int argc, char *argv[]) }if ((cmd ==CMD_LIST_SHORT || cmd ==CMD_LIST_LONG ) && enable_foreign) - conf->enable_foreign ="" ; + conf->enable_foreign =strdup ("" );/* Failing here is non-fatal */ init_foreign (conf->multipath_dir, conf->enable_foreign);
Signature · 1 line
2.28.0
PATCH 4/5 multipath-tools tests: fix memory leak in hwtable test
In reply to [email protected]From: Martin Wilck <[email protected]>
--- tests/hwtable.c | 4 ++++ 1 file changed, 4 insertions(+)
tests/hwtable.c +4 -0
@@ -25,6 +25,7 @@#include "test-lib.h" #include "print.h" #include "util.h" +#include "foreign.h" #define N_CONF_FILES 2
@@ -187,6 +188,9 @@ static int teardown(void **state)free_hwt (*state); *state =NULL ; +cleanup_prio (); +cleanup_checkers (); +cleanup_foreign ();return 0 ; }
Signature · 1 line
2.28.0
PATCH 5/5 multipath-tools tests: fix memory leak in vpd test
In reply to [email protected]From: Martin Wilck <[email protected]>
regfree() wasn't called on the re used in subst_spaces().
--- tests/vpd.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
tests/vpd.c +8 -10
@@ -28,13 +28,17 @@ struct vpdtest {char wwid[WWID_SIZE ]; }; +static regex_t space_re;static int setup (void **state) {struct vpdtest *vt =malloc (sizeof (*vt)); +int rc;if (vt ==NULL )return -1 ; *state = vt; + rc =regcomp (&space_re," +" ,REG_EXTENDED ); +assert_int_equal (rc,0 );return 0 ; }
@@ -44,6 +48,7 @@ static int teardown(void **state)free (vt); *state =NULL ; +regfree (&space_re);return 0 ; }
@@ -360,21 +365,14 @@ static char *subst_spaces(const char *src) {char *dst =calloc (1 ,strlen (src) +1 );char *p; -static regex_t *re;regmatch_t match; -int rc; +int rc =0 ;assert_non_null (dst); -if (re ==NULL ) { - re =calloc (1 ,sizeof (*re)); -assert_non_null (re); - rc =regcomp (re," +" ,REG_EXTENDED ); -assert_int_equal (rc,0 ); - } -for (rc =regexec (re, src,1 , &match,0 ), p = dst; +for (rc =regexec (&space_re, src,1 , &match,0 ), p = dst; rc ==0 ; - src += match.rm_eo, rc =regexec (re, src,1 , &match,0 )) { + src += match.rm_eo, rc =regexec (&space_re, src,1 , &match,0 )) {memcpy (p, src, match.rm_so); p += match.rm_so; *p ='_' ;
Signature · 1 line
2.28.0