From 2149869b19dc466a9190c9461c5d5a60726ebc38 Mon Sep 17 00:00:00 2001 From: Michal Shalev Date: Thu, 29 Aug 2024 04:16:48 +0300 Subject: [PATCH] UCS/VFS/BASE: convert stack allocation at ucs_vfs_node_add_subdir() to heap --- src/ucs/vfs/base/vfs_obj.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ucs/vfs/base/vfs_obj.c b/src/ucs/vfs/base/vfs_obj.c index d43ae095628d..f0dab9a6320b 100644 --- a/src/ucs/vfs/base/vfs_obj.c +++ b/src/ucs/vfs/base/vfs_obj.c @@ -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,