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 <chenrun1@xiaomi.com>
This commit is contained in:
chenrun1 2024-08-20 14:14:22 +08:00 committed by Xiang Xiao
parent 16afee6f0c
commit 36a8ff0540
2 changed files with 16 additions and 2 deletions

View File

@ -120,3 +120,9 @@ config LIBC_MAX_PATHBUFFER
---help--- ---help---
This value is the maximum size of the buffer that will hold the full This value is the maximum size of the buffer that will hold the full
file path. file path.
config LIBC_PATHBUFFER_MALLOC
bool "Enable malloc pathbuffer"
default y
---help---
Enable malloc path buffer from the heap when pathbuffer is insufficient.

View File

@ -95,9 +95,15 @@ FAR char *lib_get_pathbuffer(void)
nxmutex_unlock(&g_pathbuffer.lock); 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); 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 */ /* Free the buffer if it was dynamically allocated */
lib_free(buffer); #ifdef CONFIG_LIBC_PATHBUFFER_MALLOC
return lib_free(buffer);
#endif
} }