This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit b86baecee51f5878ad8dfb93d5203001e571f1fb Author: Marco Casaroli <[email protected]> AuthorDate: Fri Oct 30 11:59:57 2026 +0100 interpreters/bas: Give a copy of the string to putenv(). POSIX putenv() puts the string itself into the environment, it does not copy it. The ENVIRON statement gave the string of a value to putenv() and then freed it with Value_destroy(), so the environment kept a pointer to freed memory. Give putenv() a copy that stays in the environment. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- interpreters/bas/bas_statement.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/interpreters/bas/bas_statement.c b/interpreters/bas/bas_statement.c index b95a38a3c..f4bdc10bc 100644 --- a/interpreters/bas/bas_statement.c +++ b/interpreters/bas/bas_statement.c @@ -1459,8 +1459,16 @@ struct Value *stmt_ENVIRON(struct Value *value) if (g_pass == INTERPRET && value->u.string.character) { - if (putenv(value->u.string.character) == -1) + char *env; + + /* putenv() puts the string itself into the environment, and + * Value_destroy() frees the string of the value: give a copy. + */ + + env = strdup(value->u.string.character); + if (env == NULL || putenv(env) == -1) { + free(env); Value_destroy(value); g_pc = epc; return Value_new_ERROR(value, ENVIRONFAILED, strerror(errno));
