xiaoxiang781216 commented on code in PR #20583: URL: https://github.com/apache/nuttx/pull/20583#discussion_r4251168633
########## libs/libc/environ/env_sync.c: ########## @@ -0,0 +1,153 @@ +/**************************************************************************** + * libs/libc/environ/env_sync.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <errno.h> +#include <stdbool.h> + +#include <nuttx/tls.h> + +#include "environ/environ.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: env_isowned + * + * Description: + * Return true if libc allocated the string str and still owns it. + * + ****************************************************************************/ + +static bool env_isowned(FAR struct task_info_s *info, FAR const char *str) +{ + ssize_t i; + + if (info->ta_envown == NULL || str == NULL) + { + return false; + } + + for (i = 0; i < info->ta_envpc; i++) + { + if (info->ta_envown[i] == str) + { + return true; + } + } + + return false; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: env_sync + ****************************************************************************/ + +int env_sync(FAR struct task_info_s *info) Review Comment: but why need sync? could we save original sub string simply and free the copy at the end ########## libs/libc/environ/env_dup.c: ########## @@ -132,9 +133,42 @@ int env_dup(FAR struct task_info_s *info, FAR char * const *envcp) } } + /* libc allocated each string: record it as owned */ + + if (envp != NULL) + { + own = env_malloc(info, sizeof(*own) * info->ta_envpc); Review Comment: why not allocate own and envp in one env_malloc? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
