-
Notifications
You must be signed in to change notification settings - Fork 647
Reduce nsh stack consumption #2954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
|
|
||
| #include <nuttx/config.h> | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <strings.h> | ||
|
|
@@ -552,7 +553,6 @@ int cmd_timedatectl(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) | |
| #ifndef CONFIG_NSH_DISABLE_WATCH | ||
| int cmd_watch(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) | ||
| { | ||
| char buffer[LINE_MAX]; | ||
| int interval = 2; | ||
| int count = -1; | ||
| FAR char *cmd; | ||
|
|
@@ -595,8 +595,15 @@ int cmd_watch(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) | |
|
|
||
| for (i = 0; i < count; i++) | ||
| { | ||
| FAR char *buffer = lib_get_tempbuffer(LINE_MAX); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not get at line 595 & put at line 615 ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because line 613 call sleep, which may sleep for a long time. |
||
| if (buffer == NULL) | ||
| { | ||
| return ERROR; | ||
| } | ||
|
|
||
| strlcpy(buffer, cmd, LINE_MAX); | ||
| ret = nsh_parse(vtbl, buffer); | ||
| lib_put_tempbuffer(buffer); | ||
| if (ret < 0) | ||
| { | ||
| nsh_error(vtbl, g_fmtcmdfailed, argv[0], cmd, NSH_ERRNO); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @xiaoxiang781216, I believe this change was wrong;
In the fullpath is commonly allocated with strdup, e.g. in here:
nuttx-apps/nshlib/nsh_envcmds.c
Line 206 in 6028b42
And in unlink_recursive the file name is added to the fullpath in here:
nuttx-apps/nshlib/nsh_fscmds.c
Line 2170 in 6028b42
But, the size of the allocated buffer is actually just "len + 1" on the above line, since the buffer originates from strdup.
So the temporary buffer in here is not useless, it is absolutely needed.
I just found this out when I tried "rm -rf /fs/sdcard/folder", with file in in "folder". This corrupts heap and results in full system crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you are right, we need call lib_get_pathbuffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I noticed that recently with simpler
rm -rf /:-P Should we revert?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps do what @xiaoxiang781216 proposed, instead of allocating the buffer from the stack, we could use lib_get_pathbuffer to keep stack usage smaller. I can make a patch for this if so wanted...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created #3222 for the issue. @xiaoxiang781216 , @cederom please have a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlaitine thanks to fix my fault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jlaitine !! No worries @xiaoxiang781216 !! :-) <3