Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,10 @@ static int hyper_container_init(void *data)
char dev[128];
char *options = NULL;

if (container->scsiaddr)
if (container->scsiaddr) {
free(container->image);
hyper_find_sd(container->scsiaddr, &container->image);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it causes double free.
hyper_find_sd() already free it.

}

sprintf(dev, "/dev/%s", container->image);
fprintf(stdout, "device %s\n", dev);
Expand Down
26 changes: 17 additions & 9 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void hyper_sync_time_hctosys() {
}
}

int hyper_find_sd(char *addr, char **dev) {
int hyper_find_sd(char *addr, char **dev)
{
struct dirent **list;
struct dirent *dir;
char path[512];
Expand Down Expand Up @@ -152,41 +153,46 @@ int hyper_mkdir(char *hyper_path)

if (path == NULL) {
errno = ENOMEM;
return -1;
goto fail;
}

if (stat(path, &st) >= 0) {
if (S_ISDIR(st.st_mode))
return 0;
goto out;
errno = ENOTDIR;
return -1;
goto fail;
}

if (errno != ENOENT)
return -1;
goto fail;

p = strrchr(path, '/');
if (p == NULL) {
errno = EINVAL;
return -1;
goto fail;
}

if (p != path) {
*p = '\0';

if (hyper_mkdir(path) < 0)
return -1;
goto fail;

*p = '/';
}

fprintf(stdout, "create directory %s\n", path);
if (mkdir(path, 0755) < 0 && errno != EEXIST) {
perror("failed to create directory");
return -1;
goto fail;
}

out:
free(path);
return 0;

fail:
free(path);
return -1;
}

void online_cpu(void)
Expand Down Expand Up @@ -519,6 +525,8 @@ static void hyper_unmount_all(void)
fprintf(stdout, ("umount %s: %s failed\n"),
filesys, strerror(errno));
}
free(filesys);
mntlist[i] = NULL;
}

sync();
Expand Down