You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/04/17 13:22:24 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #6083: sched/environ: Refine the environment variables storage layout

xiaoxiang781216 commented on PR #6083:
URL: https://github.com/apache/incubator-nuttx/pull/6083#issuecomment-1100874550

   > This implementation is already much cleaner than the old one, thanks for fixing it.
   > 
   > My only question is how the string vectors are allocated. IMO the allocation can be done exactly once, but maybe there is some other reason for allocating memory for the vector and the strings separately.
   
   It's more efficient to allocate the array and string in one allocation for read only string(e.g. argv), but since environ string is modifiable:
   
   1. One allocation make the management more hard
   2. More important the follow code is broken:
   ```
   setenv("env1", "Hello");
   const char *env1 = getenv("env1");
   setenv("env2", "World");
   printf("%s\n", evn1);
   ```
   The last statement may access the freed memory because the 3rd statement may reallocate the whole buffer to new location.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org