mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-09 05:01:28 +00:00
util: Don't leak linksrc in vircgroup
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
14c5673d61
commit
1701ba6fdc
@ -382,6 +382,8 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
|
|||||||
FILE *mounts = NULL;
|
FILE *mounts = NULL;
|
||||||
struct mntent entry;
|
struct mntent entry;
|
||||||
char buf[CGROUP_MAX_VAL];
|
char buf[CGROUP_MAX_VAL];
|
||||||
|
char *linksrc = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
mounts = fopen(path, "r");
|
mounts = fopen(path, "r");
|
||||||
if (mounts == NULL) {
|
if (mounts == NULL) {
|
||||||
@ -409,7 +411,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typelen == len && STREQLEN(typestr, tmp, len)) {
|
if (typelen == len && STREQLEN(typestr, tmp, len)) {
|
||||||
char *linksrc;
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *tmp2;
|
char *tmp2;
|
||||||
|
|
||||||
@ -423,35 +424,35 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
|
|||||||
VIR_FREE(controller->mountPoint);
|
VIR_FREE(controller->mountPoint);
|
||||||
VIR_FREE(controller->linkPoint);
|
VIR_FREE(controller->linkPoint);
|
||||||
if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0)
|
if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
tmp2 = strrchr(entry.mnt_dir, '/');
|
tmp2 = strrchr(entry.mnt_dir, '/');
|
||||||
if (!tmp2) {
|
if (!tmp2) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Missing '/' separator in cgroup mount '%s'"),
|
_("Missing '/' separator in cgroup mount '%s'"),
|
||||||
entry.mnt_dir);
|
entry.mnt_dir);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If it is a co-mount it has a filename like "cpu,cpuacct"
|
/* If it is a co-mount it has a filename like "cpu,cpuacct"
|
||||||
* and we must identify the symlink path */
|
* and we must identify the symlink path */
|
||||||
if (checkLinks && strchr(tmp2 + 1, ',')) {
|
if (checkLinks && strchr(tmp2 + 1, ',')) {
|
||||||
*tmp2 = '\0';
|
*tmp2 = '\0';
|
||||||
|
VIR_FREE(linksrc);
|
||||||
if (virAsprintf(&linksrc, "%s/%s",
|
if (virAsprintf(&linksrc, "%s/%s",
|
||||||
entry.mnt_dir, typestr) < 0)
|
entry.mnt_dir, typestr) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
*tmp2 = '/';
|
*tmp2 = '/';
|
||||||
|
|
||||||
if (lstat(linksrc, &sb) < 0) {
|
if (lstat(linksrc, &sb) < 0) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
VIR_WARN("Controller %s co-mounted at %s is missing symlink at %s",
|
VIR_WARN("Controller %s co-mounted at %s is missing symlink at %s",
|
||||||
typestr, entry.mnt_dir, linksrc);
|
typestr, entry.mnt_dir, linksrc);
|
||||||
VIR_FREE(linksrc);
|
|
||||||
} else {
|
} else {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Cannot stat %s"),
|
_("Cannot stat %s"),
|
||||||
linksrc);
|
linksrc);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!S_ISLNK(sb.st_mode)) {
|
if (!S_ISLNK(sb.st_mode)) {
|
||||||
@ -459,6 +460,7 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
|
|||||||
linksrc, typestr);
|
linksrc, typestr);
|
||||||
} else {
|
} else {
|
||||||
controller->linkPoint = linksrc;
|
controller->linkPoint = linksrc;
|
||||||
|
linksrc = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -468,13 +470,11 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(linksrc);
|
||||||
VIR_FORCE_FCLOSE(mounts);
|
VIR_FORCE_FCLOSE(mounts);
|
||||||
|
return ret;
|
||||||
return 0;
|
|
||||||
|
|
||||||
error:
|
|
||||||
VIR_FORCE_FCLOSE(mounts);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user