diff --git a/libs/libc/misc/Kconfig b/libs/libc/misc/Kconfig index abd78dba5de..1813ba476f8 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 f82a9454a27..78ebff94ce5 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 }