Skip to contentSkip to conversation

mkfs: Fix memory leak

PATCH Superseded Pavel Reichl 2 participants 5 messages May 24, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs: Fix memory leak

'value' is allocated by strup() in getstr(). It
needs to be freed as we do not keep any permanent
reference to it.

---
 mkfs/xfs_mkfs.c | 1 +
 1 file changed, 1 insertion(+)
mkfs/xfs_mkfs.c +1 -0
index 01d2e8ca..a37d6848 100644
@@ -1714,6 +1714,7 @@ naming_opts_parser(
 		} else {
 			cli->sb_feat.dir_version = getnum(value, opts, subopt);
 		}
+		free((char *)value);
 		break;
 	case N_FTYPE:
 		cli->sb_feat.dirftype = getnum(value, opts, subopt);
Signature · 1 line
2.36.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Pavel Reichl

'value' is allocated by strup() in getstr(). It

Nit: strdup, not strup.

Quoted 4 lines

needs to be freed as we do not keep any permanent
reference to it.

With that fixed,

--D

Quoted 19 lines
---
 mkfs/xfs_mkfs.c | 1 +
 1 file changed, 1 insertion(+)
mkfs/xfs_mkfs.c +1 -0
index 01d2e8ca..a37d6848 100644
@@ -1714,6 +1714,7 @@ naming_opts_parser(
 		} else {
 			cli->sb_feat.dir_version = getnum(value, opts, subopt);
 		}
+		free((char *)value);
 		break;
 	case N_FTYPE:
 		cli->sb_feat.dirftype = getnum(value, opts, subopt);
Signature · 1 line
2.36.1
#2 lore raw
Quoted 19 lines · Darrick J. Wong
Quoted 1 line · Pavel Reichl

'value' is allocated by strup() in getstr(). It

Nit: strdup, not strup.

Quoted 4 lines

needs to be freed as we do not keep any permanent
reference to it.

With that fixed,

--D

Quoted 4 lines
---
 mkfs/xfs_mkfs.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 9 lines

mkfs/xfs_mkfs.c naming_opts_parser( · line 1717

Quoted 9 lines
mkfs/xfs_mkfs.c +1 -0
index 01d2e8ca..a37d6848 100644
@@ -1714,6 +1714,7 @@ naming_opts_parser(
 		} else {
 			cli->sb_feat.dir_version = getnum(value, opts, subopt);
 		}
+		free((char *)value);

...well, that, and the ^^^^ cast here isn't necessary.

--D

Quoted 6 lines
Quoted 6 lines
mkfs/xfs_mkfs.c +0 -0
 		break;
 	case N_FTYPE:
 		cli->sb_feat.dirftype = getnum(value, opts, subopt);
Signature · 1 line
2.36.1
#3 lore raw
Quoted 29 lines · Darrick J. Wong
Quoted 17 lines · Darrick J. Wong
Quoted 1 line · Pavel Reichl

'value' is allocated by strup() in getstr(). It

Nit: strdup, not strup.

Quoted 4 lines

needs to be freed as we do not keep any permanent
reference to it.

With that fixed,

--D

Quoted 4 lines
---
  mkfs/xfs_mkfs.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 9 lines

mkfs/xfs_mkfs.c naming_opts_parser( · line 1717

Quoted 9 lines
mkfs/xfs_mkfs.c +1 -0
index 01d2e8ca..a37d6848 100644
@@ -1714,6 +1714,7 @@ naming_opts_parser(
  		} else {
  			cli->sb_feat.dir_version = getnum(value, opts, subopt);
  		}
+		free((char *)value);

...well, that, and the ^^^^ cast here isn't necessary.

Quoted 1 line

--D

Hi,

thanks for the comment, but w/o the cast I get this warning

xfs_mkfs.c:1717:22: warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 1717 |                 free(value);
      |                      ^~~~~
In file included from ../include/platform_defs.h:16,
                 from ../include/libxfs.h:11,
                 from xfs_mkfs.c:7:
/usr/include/stdlib.h:555:25: note: expected ‘void *’ but argument is of type ‘const char *’
  555 | extern void free (void *__ptr) __THROW;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
mkfs/xfs_mkfs.c +0 -0
  		break;
  	case N_FTYPE:
  		cli->sb_feat.dirftype = getnum(value, opts, subopt);
Signature · 1 line
2.36.1
#4 lore raw
Quoted 37 lines · Pavel Reichl
Quoted 29 lines · Darrick J. Wong
Quoted 17 lines · Darrick J. Wong
Quoted 1 line · Pavel Reichl

'value' is allocated by strup() in getstr(). It

Nit: strdup, not strup.

Quoted 4 lines

needs to be freed as we do not keep any permanent
reference to it.

With that fixed,

--D

Quoted 4 lines
---
  mkfs/xfs_mkfs.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 9 lines

mkfs/xfs_mkfs.c naming_opts_parser( · line 1717

Quoted 9 lines
mkfs/xfs_mkfs.c +1 -0
index 01d2e8ca..a37d6848 100644
@@ -1714,6 +1714,7 @@ naming_opts_parser(
  		} else {
  			cli->sb_feat.dir_version = getnum(value, opts, subopt);
  		}
+		free((char *)value);

...well, that, and the ^^^^ cast here isn't necessary.

Quoted 1 line

--D

Hi,

thanks for the comment, but w/o the cast I get this warning

Quoted 10 lines

xfs_mkfs.c:1717:22: warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 1717 |                 free(value);
      |                      ^~~~~
In file included from ../include/platform_defs.h:16,
                 from ../include/libxfs.h:11,
                 from xfs_mkfs.c:7:
/usr/include/stdlib.h:555:25: note: expected ‘void *’ but argument is of type ‘const char *’
  555 | extern void free (void *__ptr) __THROW;

Ah, ok. Ignore my comment then. :)

--D

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
mkfs/xfs_mkfs.c +0 -0
  		break;
  	case N_FTYPE:
  		cli->sb_feat.dirftype = getnum(value, opts, subopt);
Signature · 1 line
2.36.1