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

Commit 1378887

Browse files
committed
fix memory leak in hyper_find_virtio_port
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
1 parent a8212f6 commit 1378887

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/util.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ char* hyper_find_virtio_port(char *channel)
649649
struct dirent **list;
650650
struct dirent *dir;
651651
int fd = -1, i, num;
652-
char path[256], name[128];
652+
char path[256], name[128], *ret = NULL;
653653

654654
num = scandir("/sys/class/virtio-ports/", &list, NULL, NULL);
655655
if (num < 0) {
@@ -690,12 +690,13 @@ char* hyper_find_virtio_port(char *channel)
690690
}
691691

692692
fprintf(stdout, "find hyper channel %s\n", path);
693-
free(list);
694-
return strdup(path);
693+
ret = strdup(path);
695694
}
696695

696+
for (i = 0; i < num; i++)
697+
free(list[i]);
697698
free(list);
698-
return NULL;
699+
return ret;
699700
}
700701

701702
int hyper_setfd_cloexec(int fd)

0 commit comments

Comments
 (0)