Skip to content

Commit 339eeaa

Browse files
Zhangshoukuixiaoxiang781216
authored andcommitted
Use lib_get_tempbuffer Saving stack
Signed-off-by: zhangshoukui <[email protected]>
1 parent 4685ca5 commit 339eeaa

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

nshlib/nsh_mmcmds.c

+19-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <nuttx/config.h>
2828

29+
#include <stdio.h>
2930
#include <string.h>
3031

3132
#include "nsh.h"
@@ -58,18 +59,29 @@ int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
5859

5960
int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
6061
{
61-
char arg[LINE_MAX] = "";
62+
FAR char *arg;
63+
int ret;
6264
int i;
6365

66+
arg = lib_get_tempbuffer(LINE_MAX);
67+
if (arg == NULL)
68+
{
69+
return -ENOMEM;
70+
}
71+
72+
arg[0] = '\0';
73+
6474
if (argc == 1)
6575
{
6676
strlcpy(arg, "used", LINE_MAX);
6777
}
6878
else if (argc >= 2 && (strcmp(argv[1], "-h") == 0 ||
6979
strcmp(argv[1], "help") == 0))
7080
{
71-
return nsh_catfile(vtbl, argv[0],
72-
CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
81+
ret = nsh_catfile(vtbl, argv[0],
82+
CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
83+
lib_put_tempbuffer(arg);
84+
return ret;
7385
}
7486
else
7587
{
@@ -83,8 +95,10 @@ int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
8395
}
8496
}
8597

86-
return nsh_writefile(vtbl, argv[0], arg, strlen(arg),
87-
CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
98+
ret = nsh_writefile(vtbl, argv[0], arg, strlen(arg),
99+
CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
100+
lib_put_tempbuffer(arg);
101+
return ret;
88102
}
89103

90104
#endif /* !CONFIG_NSH_DISABLE_MEMDUMP && NSH_HAVE_WRITEFILE */

0 commit comments

Comments
 (0)