This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 36a8ff0540ca7389b5a14b64149a96f4f7a23461 Author: chenrun1 <[email protected]> AuthorDate: Tue Aug 20 14:14:22 2024 +0800 lib_pathbuffer.c:Determine whether to malloc from the heap by CONFIG_LIBC_PATHBUFFER_MALLOC Summary: If we disable LIB_PATHBUFFER_MALLOC, that when the path buffer is insufficient, NULL is returned to avoid applying for a buffer from the heap. Signed-off-by: chenrun1 <[email protected]> --- libs/libc/misc/Kconfig | 6 ++++++ libs/libc/misc/lib_pathbuffer.c | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libs/libc/misc/Kconfig b/libs/libc/misc/Kconfig index abd78dba5d..1813ba476f 100644 --- a/libs/libc/misc/Kconfig +++ b/libs/libc/misc/Kconfig @@ -120,3 +120,9 @@ config LIBC_MAX_PATHBUFFER ---help--- This value is the maximum size of the buffer that will hold the full file path. + +config LIBC_PATHBUFFER_MALLOC + bool "Enable malloc pathbuffer" + default y + ---help--- + Enable malloc path buffer from the heap when pathbuffer is insufficient. diff --git a/libs/libc/misc/lib_pathbuffer.c b/libs/libc/misc/lib_pathbuffer.c index f82a9454a2..78ebff94ce 100644 --- a/libs/libc/misc/lib_pathbuffer.c +++ b/libs/libc/misc/lib_pathbuffer.c @@ -95,9 +95,15 @@ FAR char *lib_get_pathbuffer(void) nxmutex_unlock(&g_pathbuffer.lock); - /* If no free buffer is found, allocate a new one */ + /* If no free buffer is found, allocate a new one if + * CONFIG_LIBC_PATHBUFFER_MALLOC is enabled + */ +#ifdef CONFIG_LIBC_PATHBUFFER_MALLOC return lib_malloc(PATH_MAX); +#else + return NULL; +#endif } /**************************************************************************** @@ -134,5 +140,7 @@ void lib_put_pathbuffer(FAR char *buffer) /* Free the buffer if it was dynamically allocated */ - lib_free(buffer); +#ifdef CONFIG_LIBC_PATHBUFFER_MALLOC + return lib_free(buffer); +#endif }
