* [PATCH v2 iproute2] lnstat: fix strdup leak in -w argument parsing
@ 2022-02-16 20:35 Maxim Petrov
2022-02-16 21:03 ` Stephen Hemminger
0 siblings, 1 reply; 2+ messages in thread
From: Maxim Petrov @ 2022-02-16 20:35 UTC (permalink / raw)
To: netdev; +Cc: Stephen Hemminger
'tmp' string is copied for safe tokenizing, but it is not required after
getting all the widths in -w option. Use strdupa instead of strdup to avoid
explicit memory leak and to not trigger valgrind here.
Signed-off-by: Maxim Petrov <mmrmaximuzz@gmail.com>
---
Changes in V2:
* Use strdupa instead of strdup/free
misc/lnstat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/misc/lnstat.c b/misc/lnstat.c
index 98904d45..d7e1d8c9 100644
--- a/misc/lnstat.c
+++ b/misc/lnstat.c
@@ -314,7 +314,7 @@ int main(int argc, char **argv)
sscanf(optarg, "%u", &hdr);
break;
case 'w':
- tmp = strdup(optarg);
+ tmp = strdupa(optarg);
if (!tmp)
break;
i = 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2 iproute2] lnstat: fix strdup leak in -w argument parsing
2022-02-16 20:35 [PATCH v2 iproute2] lnstat: fix strdup leak in -w argument parsing Maxim Petrov
@ 2022-02-16 21:03 ` Stephen Hemminger
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2022-02-16 21:03 UTC (permalink / raw)
To: Maxim Petrov; +Cc: netdev
On Wed, 16 Feb 2022 23:35:43 +0300
Maxim Petrov <mmrmaximuzz@gmail.com> wrote:
> 'tmp' string is copied for safe tokenizing, but it is not required after
> getting all the widths in -w option. Use strdupa instead of strdup to avoid
> explicit memory leak and to not trigger valgrind here.
>
> Signed-off-by: Maxim Petrov <mmrmaximuzz@gmail.com>
> ---
> Changes in V2:
> * Use strdupa instead of strdup/free
>
> misc/lnstat.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/misc/lnstat.c b/misc/lnstat.c
> index 98904d45..d7e1d8c9 100644
> --- a/misc/lnstat.c
> +++ b/misc/lnstat.c
> @@ -314,7 +314,7 @@ int main(int argc, char **argv)
> sscanf(optarg, "%u", &hdr);
> break;
> case 'w':
> - tmp = strdup(optarg);
> + tmp = strdupa(optarg);
> if (!tmp)
> break;
> i = 0;
I went with your earlier patch, just was asking.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-16 21:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-16 20:35 [PATCH v2 iproute2] lnstat: fix strdup leak in -w argument parsing Maxim Petrov
2022-02-16 21:03 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).