mkfs: Fix memory leak
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
@@ -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
Quoted 1 line · Pavel Reichl
'value' is allocated by
strup()ingetstr(). It
Nit: strdup, not strup.
Quoted 4 lines
needs to be freed as we do not keep any permanent
reference to it.Signed-off-by Pavel Reichl <[email protected]>
With that fixed,
--D
Quoted 19 lines
--- mkfs/xfs_mkfs.c | 1 + 1 file changed, 1 insertion(+)mkfs/xfs_mkfs.c +1
-0@@ -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
Quoted 19 lines · Darrick J. Wong
Quoted 1 line · Pavel Reichl
'value' is allocated by
strup()ingetstr(). ItNit: strdup, not strup.
Quoted 4 lines
needs to be freed as we do not keep any permanent
reference to it.Signed-off-by Pavel Reichl <[email protected]>With that fixed,
Reviewed-by Darrick J. Wong <[email protected]>--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@@ -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
-0break ;case N_FTYPE : cli->sb_feat.dirftype =getnum (value, opts, subopt);Signature · 1 line
2.36.1
Quoted 29 lines · Darrick J. Wong
Quoted 17 lines · Darrick J. Wong
Quoted 1 line · Pavel Reichl
'value' is allocated by
strup()ingetstr(). ItNit: strdup, not strup.
Quoted 4 lines
needs to be freed as we do not keep any permanent
reference to it.Signed-off-by Pavel Reichl <[email protected]>With that fixed,
Reviewed-by Darrick J. Wong <[email protected]>--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@@ -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
-0break ;case N_FTYPE : cli->sb_feat.dirftype =getnum (value, opts, subopt);Signature · 1 line
2.36.1
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()ingetstr(). ItNit: strdup, not strup.
Quoted 4 lines
needs to be freed as we do not keep any permanent
reference to it.Signed-off-by Pavel Reichl <[email protected]>With that fixed,
Reviewed-by Darrick J. Wong <[email protected]>--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@@ -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
-0break ;case N_FTYPE : cli->sb_feat.dirftype =getnum (value, opts, subopt);Signature · 1 line
2.36.1