mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
storage: avoid memory leak
Coverity detected that options was being set by strdup but never
freed. But why even bother with an options variable? The options
parameter never changes! Leak present since commit 44948f5b
(0.7.0).
This function could probably be rewritten to take better advantage
of virCommand, but that is more invasive.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemMount): Avoid wasted strdup, and
guarantee proper cleanup on all paths.
This commit is contained in:
parent
ef21bedaf9
commit
9892f7bca0
@ -317,7 +317,6 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool) {
|
|||||||
static int
|
static int
|
||||||
virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
|
virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
|
||||||
char *src;
|
char *src;
|
||||||
char *options = NULL;
|
|
||||||
const char **mntargv;
|
const char **mntargv;
|
||||||
|
|
||||||
/* 'mount -t auto' doesn't seem to auto determine nfs (or cifs),
|
/* 'mount -t auto' doesn't seem to auto determine nfs (or cifs),
|
||||||
@ -328,7 +327,6 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
|
|||||||
int glusterfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
|
int glusterfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
|
||||||
pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);
|
pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);
|
||||||
|
|
||||||
int option_index;
|
|
||||||
int source_index;
|
int source_index;
|
||||||
|
|
||||||
const char *netfs_auto_argv[] = {
|
const char *netfs_auto_argv[] = {
|
||||||
@ -358,7 +356,7 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
|
|||||||
virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
|
virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
|
||||||
NULL,
|
NULL,
|
||||||
"-o",
|
"-o",
|
||||||
NULL,
|
"direct-io-mode=1",
|
||||||
pool->def->target.path,
|
pool->def->target.path,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
@ -369,7 +367,6 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
|
|||||||
} else if (glusterfs) {
|
} else if (glusterfs) {
|
||||||
mntargv = glusterfs_argv;
|
mntargv = glusterfs_argv;
|
||||||
source_index = 3;
|
source_index = 3;
|
||||||
option_index = 5;
|
|
||||||
} else {
|
} else {
|
||||||
mntargv = fs_argv;
|
mntargv = fs_argv;
|
||||||
source_index = 3;
|
source_index = 3;
|
||||||
@ -405,12 +402,6 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
|
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
|
||||||
if (pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS) {
|
|
||||||
if ((options = strdup("direct-io-mode=1")) == NULL) {
|
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (virAsprintf(&src, "%s:%s",
|
if (virAsprintf(&src, "%s:%s",
|
||||||
pool->def->source.host.name,
|
pool->def->source.host.name,
|
||||||
pool->def->source.dir) == -1) {
|
pool->def->source.dir) == -1) {
|
||||||
@ -426,10 +417,6 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
|
|||||||
}
|
}
|
||||||
mntargv[source_index] = src;
|
mntargv[source_index] = src;
|
||||||
|
|
||||||
if (glusterfs) {
|
|
||||||
mntargv[option_index] = options;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virRun(mntargv, NULL) < 0) {
|
if (virRun(mntargv, NULL) < 0) {
|
||||||
VIR_FREE(src);
|
VIR_FREE(src);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user