Skip to content

Commit

Permalink
Merge pull request torvalds#270 from libos-nuse/fix-lkl-malloc
Browse files Browse the repository at this point in the history
lkl: avoid using libc function (i.e., free(3)) for non-libc environment
  • Loading branch information
tavip authored Nov 21, 2016
2 parents 189a2c7 + d299572 commit ac79c65
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tools/lkl/lib/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ac79c65

Please sign in to comment.