mirror of
https://github.com/apache/nuttx.git
synced 2026-08-28 21:00:44 +00:00
fs/inode: change fs_heap to lib_get_tempbuffer/lib_put_tempbuffer
Replace the fs_heap_asprintf()/fs_heap_free() based allocation of the path buffer in the inode search with the lib_get_tempbuffer()/ lib_put_tempbuffer() pool. Fixed PATH_MAX sized temporary buffers avoid per-call heap allocation and keep the buffer allocator consistent with the rest of the path-resolution code. Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
This commit is contained in:
parent
8c7ca1fb0e
commit
4fb02e8766
2 changed files with 13 additions and 16 deletions
|
|
@ -36,7 +36,6 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "fs_heap.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
|
|
@ -351,19 +350,19 @@ static int _inode_search(FAR struct inode_search_s *desc)
|
|||
{
|
||||
FAR char *buffer = NULL;
|
||||
|
||||
ret = fs_heap_asprintf(&buffer, "%s/%s",
|
||||
desc->relpath,
|
||||
name);
|
||||
if (ret > 0)
|
||||
buffer = lib_get_tempbuffer(PATH_MAX);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
fs_heap_free(desc->buffer);
|
||||
desc->buffer = buffer;
|
||||
relpath = buffer;
|
||||
ret = OK;
|
||||
ret = -ENOMEM;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -ENOMEM;
|
||||
snprintf(buffer, PATH_MAX, "%s/%s",
|
||||
desc->relpath, name);
|
||||
lib_put_tempbuffer(desc->buffer);
|
||||
desc->buffer = buffer;
|
||||
relpath = buffer;
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -493,13 +492,13 @@ int inode_search(FAR struct inode_search_s *desc)
|
|||
|
||||
if (*desc->path != '/')
|
||||
{
|
||||
ret = fs_heap_asprintf(&desc->buffer, "%s/%s",
|
||||
_inode_getcwd(), desc->path);
|
||||
if (ret < 0)
|
||||
desc->buffer = lib_get_tempbuffer(PATH_MAX);
|
||||
if (desc->buffer == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
snprintf(desc->buffer, PATH_MAX, "%s/%s", _inode_getcwd(), desc->path);
|
||||
desc->path = desc->buffer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/lib/lib.h>
|
||||
|
||||
#include "fs_heap.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
|
@ -65,7 +63,7 @@
|
|||
{ \
|
||||
if ((d)->buffer != NULL) \
|
||||
{ \
|
||||
fs_heap_free((d)->buffer); \
|
||||
lib_put_tempbuffer((d)->buffer); \
|
||||
(d)->buffer = NULL; \
|
||||
} \
|
||||
} \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue