Skip to content

Commit 36a8ff0

Browse files
crafcat7xiaoxiang781216
authored andcommitted
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]>
1 parent 16afee6 commit 36a8ff0

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

libs/libc/misc/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,9 @@ config LIBC_MAX_PATHBUFFER
120120
---help---
121121
This value is the maximum size of the buffer that will hold the full
122122
file path.
123+
124+
config LIBC_PATHBUFFER_MALLOC
125+
bool "Enable malloc pathbuffer"
126+
default y
127+
---help---
128+
Enable malloc path buffer from the heap when pathbuffer is insufficient.

libs/libc/misc/lib_pathbuffer.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,15 @@ FAR char *lib_get_pathbuffer(void)
9595

9696
nxmutex_unlock(&g_pathbuffer.lock);
9797

98-
/* If no free buffer is found, allocate a new one */
98+
/* If no free buffer is found, allocate a new one if
99+
* CONFIG_LIBC_PATHBUFFER_MALLOC is enabled
100+
*/
99101

102+
#ifdef CONFIG_LIBC_PATHBUFFER_MALLOC
100103
return lib_malloc(PATH_MAX);
104+
#else
105+
return NULL;
106+
#endif
101107
}
102108

103109
/****************************************************************************
@@ -134,5 +140,7 @@ void lib_put_pathbuffer(FAR char *buffer)
134140

135141
/* Free the buffer if it was dynamically allocated */
136142

137-
lib_free(buffer);
143+
#ifdef CONFIG_LIBC_PATHBUFFER_MALLOC
144+
return lib_free(buffer);
145+
#endif
138146
}

0 commit comments

Comments
 (0)