Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 402a930

Browse files
committed
Merge pull request #85 from bergwolf/strdup
fix a few strdup memory leaks
2 parents 84207a3 + 4475e2d commit 402a930

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/container.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,10 @@ static int hyper_container_init(void *data)
523523
char dev[128];
524524
char *options = NULL;
525525

526-
if (container->scsiaddr)
526+
if (container->scsiaddr) {
527+
free(container->image);
527528
hyper_find_sd(container->scsiaddr, &container->image);
529+
}
528530

529531
sprintf(dev, "/dev/%s", container->image);
530532
fprintf(stdout, "device %s\n", dev);

src/util.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ void hyper_sync_time_hctosys() {
111111
}
112112
}
113113

114-
int hyper_find_sd(char *addr, char **dev) {
114+
int hyper_find_sd(char *addr, char **dev)
115+
{
115116
struct dirent **list;
116117
struct dirent *dir;
117118
char path[512];
@@ -152,41 +153,46 @@ int hyper_mkdir(char *hyper_path)
152153

153154
if (path == NULL) {
154155
errno = ENOMEM;
155-
return -1;
156+
goto fail;
156157
}
157158

158159
if (stat(path, &st) >= 0) {
159160
if (S_ISDIR(st.st_mode))
160-
return 0;
161+
goto out;
161162
errno = ENOTDIR;
162-
return -1;
163+
goto fail;
163164
}
164165

165166
if (errno != ENOENT)
166-
return -1;
167+
goto fail;
167168

168169
p = strrchr(path, '/');
169170
if (p == NULL) {
170171
errno = EINVAL;
171-
return -1;
172+
goto fail;
172173
}
173174

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

177178
if (hyper_mkdir(path) < 0)
178-
return -1;
179+
goto fail;
179180

180181
*p = '/';
181182
}
182183

183184
fprintf(stdout, "create directory %s\n", path);
184185
if (mkdir(path, 0755) < 0 && errno != EEXIST) {
185186
perror("failed to create directory");
186-
return -1;
187+
goto fail;
187188
}
188-
189+
out:
190+
free(path);
189191
return 0;
192+
193+
fail:
194+
free(path);
195+
return -1;
190196
}
191197

192198
void online_cpu(void)
@@ -519,6 +525,8 @@ static void hyper_unmount_all(void)
519525
fprintf(stdout, ("umount %s: %s failed\n"),
520526
filesys, strerror(errno));
521527
}
528+
free(filesys);
529+
mntlist[i] = NULL;
522530
}
523531

524532
sync();

0 commit comments

Comments
 (0)