* [PATCH] mkfs: Fix memory leak
@ 2022-05-24 20:40 Pavel Reichl
2022-05-24 21:06 ` Darrick J. Wong
0 siblings, 1 reply; 5+ messages in thread
From: Pavel Reichl @ 2022-05-24 20:40 UTC (permalink / raw)
To: linux-xfs
'value' is allocated by strup() in getstr(). It
needs to be freed as we do not keep any permanent
reference to it.
Signed-off-by: Pavel Reichl <preichl@redhat.com>
---
mkfs/xfs_mkfs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 01d2e8ca..a37d6848 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -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);
--
2.36.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mkfs: Fix memory leak
2022-05-24 20:40 [PATCH] mkfs: Fix memory leak Pavel Reichl
@ 2022-05-24 21:06 ` Darrick J. Wong
2022-05-24 21:08 ` Darrick J. Wong
0 siblings, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2022-05-24 21:06 UTC (permalink / raw)
To: Pavel Reichl; +Cc: linux-xfs
On Tue, May 24, 2022 at 10:40:40PM +0200, Pavel Reichl wrote:
> 'value' is allocated by strup() in getstr(). It
Nit: strdup, not strup.
> needs to be freed as we do not keep any permanent
> reference to it.
>
> Signed-off-by: Pavel Reichl <preichl@redhat.com>
With that fixed,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
> mkfs/xfs_mkfs.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index 01d2e8ca..a37d6848 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -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);
> --
> 2.36.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mkfs: Fix memory leak
2022-05-24 21:06 ` Darrick J. Wong
@ 2022-05-24 21:08 ` Darrick J. Wong
2022-05-24 21:13 ` Pavel Reichl
0 siblings, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2022-05-24 21:08 UTC (permalink / raw)
To: Pavel Reichl; +Cc: linux-xfs
On Tue, May 24, 2022 at 02:06:44PM -0700, Darrick J. Wong wrote:
> On Tue, May 24, 2022 at 10:40:40PM +0200, Pavel Reichl wrote:
> > 'value' is allocated by strup() in getstr(). It
>
> Nit: strdup, not strup.
>
> > needs to be freed as we do not keep any permanent
> > reference to it.
> >
> > Signed-off-by: Pavel Reichl <preichl@redhat.com>
>
> With that fixed,
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
>
> --D
>
> > ---
> > mkfs/xfs_mkfs.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> > index 01d2e8ca..a37d6848 100644
> > --- a/mkfs/xfs_mkfs.c
> > +++ b/mkfs/xfs_mkfs.c
> > @@ -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
> > break;
> > case N_FTYPE:
> > cli->sb_feat.dirftype = getnum(value, opts, subopt);
> > --
> > 2.36.1
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mkfs: Fix memory leak
2022-05-24 21:08 ` Darrick J. Wong
@ 2022-05-24 21:13 ` Pavel Reichl
2022-05-24 21:27 ` Darrick J. Wong
0 siblings, 1 reply; 5+ messages in thread
From: Pavel Reichl @ 2022-05-24 21:13 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs
On 5/24/22 23:08, Darrick J. Wong wrote:
> On Tue, May 24, 2022 at 02:06:44PM -0700, Darrick J. Wong wrote:
>> On Tue, May 24, 2022 at 10:40:40PM +0200, Pavel Reichl wrote:
>>> 'value' is allocated by strup() in getstr(). It
>> Nit: strdup, not strup.
>>
>>> needs to be freed as we do not keep any permanent
>>> reference to it.
>>>
>>> Signed-off-by: Pavel Reichl <preichl@redhat.com>
>> With that fixed,
>> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
>>
>> --D
>>
>>> ---
>>> mkfs/xfs_mkfs.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
>>> index 01d2e8ca..a37d6848 100644
>>> --- a/mkfs/xfs_mkfs.c
>>> +++ b/mkfs/xfs_mkfs.c
>>> @@ -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
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;
>
>>> break;
>>> case N_FTYPE:
>>> cli->sb_feat.dirftype = getnum(value, opts, subopt);
>>> --
>>> 2.36.1
>>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mkfs: Fix memory leak
2022-05-24 21:13 ` Pavel Reichl
@ 2022-05-24 21:27 ` Darrick J. Wong
0 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2022-05-24 21:27 UTC (permalink / raw)
To: Pavel Reichl; +Cc: linux-xfs
On Tue, May 24, 2022 at 11:13:01PM +0200, Pavel Reichl wrote:
>
> On 5/24/22 23:08, Darrick J. Wong wrote:
> > On Tue, May 24, 2022 at 02:06:44PM -0700, Darrick J. Wong wrote:
> > > On Tue, May 24, 2022 at 10:40:40PM +0200, Pavel Reichl wrote:
> > > > 'value' is allocated by strup() in getstr(). It
> > > Nit: strdup, not strup.
> > >
> > > > needs to be freed as we do not keep any permanent
> > > > reference to it.
> > > >
> > > > Signed-off-by: Pavel Reichl <preichl@redhat.com>
> > > With that fixed,
> > > Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> > >
> > > --D
> > >
> > > > ---
> > > > mkfs/xfs_mkfs.c | 1 +
> > > > 1 file changed, 1 insertion(+)
> > > >
> > > > diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> > > > index 01d2e8ca..a37d6848 100644
> > > > --- a/mkfs/xfs_mkfs.c
> > > > +++ b/mkfs/xfs_mkfs.c
> > > > @@ -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
>
> 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;
Ah, ok. Ignore my comment then. :)
--D
>
> >
> > > > break;
> > > > case N_FTYPE:
> > > > cli->sb_feat.dirftype = getnum(value, opts, subopt);
> > > > --
> > > > 2.36.1
> > > >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-05-24 21:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24 20:40 [PATCH] mkfs: Fix memory leak Pavel Reichl
2022-05-24 21:06 ` Darrick J. Wong
2022-05-24 21:08 ` Darrick J. Wong
2022-05-24 21:13 ` Pavel Reichl
2022-05-24 21:27 ` Darrick J. Wong
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.