lnstat: fix strdup leak in -w argument parsing
Subsystems (2)
PATCH v2 1/1 lnstat: fix strdup leak in -w argument parsing
'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 <[email protected]>
---
Changes in V2:
* Use strdupa instead of strdup/free
misc/lnstat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
misc/lnstat.c +1 -1
@@ -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 ;
Signature · 1 line
2.25.1
Quoted 17 lines · On Wed, 16 Feb 2022 23:35:43 +0300 Maxim Petrov <[email protected]> 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 <[email protected]>---
Changes in V2:
* Use strdupa instead of strdup/freemisc/lnstat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)misc/lnstat.c +0
-0
misc/lnstat.c int main(int argc, char **argv) · line 320
Quoted 8 lines
misc/lnstat.c +1
-1@@ -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.