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

Commit 9cba4d0

Browse files
authored
Merge pull request #350 from keloyang/scandir-mem-leak
hyperstart: fix several mem leak
2 parents 7670d5e + bde26da commit 9cba4d0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/container.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,19 @@ static int container_setup_modules(struct hyper_container *container)
264264
if (stat(dst, &st) == 0) {
265265
struct dirent **list;
266266
int num;
267+
int i;
267268

268269
if (!S_ISDIR(st.st_mode)) {
269270
return -1;
270271
}
271272

272273
num = scandir(dst, &list, NULL, NULL);
274+
if (num > 1) {
275+
for (i = 0; i < num; i++) {
276+
free(list[i]);
277+
}
278+
free(list);
279+
}
273280
if (num > 2) {
274281
fprintf(stdout, "%s is not null, %d", dst, num);
275282
return 0;
@@ -530,8 +537,11 @@ static int hyper_rescan_scsi(void)
530537
}
531538

532539
fprintf(stdout, "finish scan scsi\n");
533-
return 0;
540+
for (i = 0; i < num; i++) {
541+
free(list[i]);
542+
}
534543
free(list);
544+
return 0;
535545
}
536546

537547
struct hyper_container_arg {

0 commit comments

Comments
 (0)