Skip to content

Commit

Permalink
UCS/VFS/BASE: convert stack allocation at ucs_vfs_node_add_subdir() t…
Browse files Browse the repository at this point in the history
…o heap
  • Loading branch information
michal-shalev committed Sep 5, 2024
1 parent e7664c4 commit 8cb5ec5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ucs/vfs/base/vfs_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,26 @@ static void ucs_vfs_node_build_path(ucs_vfs_node_t *parent_node,
static ucs_vfs_node_t *
ucs_vfs_node_add_subdir(ucs_vfs_node_t *parent_node, const char *name)
{
char path_buf[PATH_MAX];
char *path_buf = ucs_malloc(PATH_MAX, "path_buf");
ucs_vfs_node_t *node;

ucs_vfs_node_build_path(parent_node, name, path_buf, sizeof(path_buf));
if (path_buf == NULL) {
ucs_error("failed to allocate memory for path_buf");
return NULL;
}

ucs_vfs_node_build_path(parent_node, name, path_buf, PATH_MAX);
node = ucs_vfs_node_find_by_path(path_buf);
if (node != NULL) {
ucs_free(path_buf);
return node;
}

return ucs_vfs_node_create(parent_node, path_buf, UCS_VFS_NODE_TYPE_SUBDIR,
node = ucs_vfs_node_create(parent_node, path_buf, UCS_VFS_NODE_TYPE_SUBDIR,
NULL);
ucs_free(path_buf);

return node;
}

static int ucs_vfs_node_need_update_path(ucs_vfs_node_type_t type,
Expand Down

0 comments on commit 8cb5ec5

Please sign in to comment.