NSH library: malloc/free IOBUFFER instead of using stack

This commit is contained in:
Gregory Nutt
2014-04-21 18:12:59 -06:00
parent a2600cbe83
commit 03ec268ef9
3 changed files with 21 additions and 3 deletions

View File

@@ -373,7 +373,7 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#ifndef CONFIG_NSH_DISABLE_HEXDUMP
int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
uint8_t buffer[IOBUFFERSIZE];
FAR uint8_t *buffer;
char msg[32];
off_t position;
int fd;
@@ -394,6 +394,13 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ERROR;
}
buffer = (FAR uint8_t *)malloc(IOBUFFERSIZE);
if(buffer == NULL)
{
nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "malloc", NSH_ERRNO);
return ERROR;
}
#ifdef CONFIG_NSH_CMDOPT_HEXDUMP
for (x = 2; x < argc; x++)
{
@@ -489,6 +496,7 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
(void)close(fd);
free(buffer);
return ret;
}
#endif