mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-20 04:26:04 +08:00
NSH library: malloc/free IOBUFFER instead of using stack
This commit is contained in:
@@ -416,7 +416,7 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath,
|
||||
static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
FAR const char *filename)
|
||||
{
|
||||
char buffer[IOBUFFERSIZE];
|
||||
FAR char *buffer;
|
||||
int fd;
|
||||
int ret = OK;
|
||||
|
||||
@@ -429,6 +429,13 @@ static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
buffer = (FAR char *)malloc(IOBUFFERSIZE);
|
||||
if(buffer == NULL)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, cmd, "malloc", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* And just dump it byte for byte into stdout */
|
||||
|
||||
for (;;)
|
||||
@@ -514,6 +521,7 @@ static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
/* Close the input file and return the result */
|
||||
|
||||
(void)close(fd);
|
||||
free(buffer);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user