diff --git a/tools/lkl/lib/fs.c b/tools/lkl/lib/fs.c index f3481f8b194017..43fcf4fd05b163 100644 --- a/tools/lkl/lib/fs.c +++ b/tools/lkl/lib/fs.c @@ -55,7 +55,9 @@ static char *get_node_with_prefix(const char *path, const char *prefix, while ((dirent = lkl_readdir(dir))) { if (startswith(dirent->d_name, prefix)) { - result = strdup(dirent->d_name); + result = lkl_host_ops.mem_alloc(strlen(dirent->d_name) + 1); + memcpy(result, dirent->d_name, strlen(dirent->d_name)); + result[strlen(dirent->d_name)] = '\0'; break; } } @@ -102,7 +104,7 @@ int lkl_get_virtio_blkdev(int disk_id, uint32_t *pdevid) ret = snprintf(sysfs_path + sysfs_path_len, sizeof(sysfs_path) - sysfs_path_len, "/%s/block", virtio_name); - free(virtio_name); + lkl_host_ops.mem_free(virtio_name); if (ret < 0 || (size_t) ret >= sizeof(sysfs_path) - sysfs_path_len) return -LKL_ENOMEM; sysfs_path_len += ret; @@ -113,7 +115,7 @@ int lkl_get_virtio_blkdev(int disk_id, uint32_t *pdevid) ret = snprintf(sysfs_path + sysfs_path_len, sizeof(sysfs_path) - sysfs_path_len, "/%s/dev", disk_name); - free(disk_name); + lkl_host_ops.mem_free(disk_name); if (ret < 0 || (size_t) ret >= sizeof(sysfs_path) - sysfs_path_len) return -LKL_ENOMEM; sysfs_path_len += ret;