diff --git a/src/libvirt.c b/src/libvirt.c index 988320447b..eeaf0b6145 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -11860,7 +11860,8 @@ error: * pool documentation for information on getting the * persistent naming * - * Returns the storage volume path, or NULL on error + * Returns the storage volume path, or NULL on error. The + * caller must free() the returned path after use. */ char * virStorageVolGetPath(virStorageVolPtr vol) diff --git a/tools/virsh.c b/tools/virsh.c index 57aded30b7..61f69f05bc 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -9320,6 +9320,7 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd) { virStorageVolPtr vol; const char *name = NULL; + char * StorageVolPath; if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -9328,7 +9329,13 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd) return false; } - vshPrint(ctl, "%s\n", virStorageVolGetPath(vol)); + if ((StorageVolPath = virStorageVolGetPath(vol)) == NULL) { + virStorageVolFree(vol); + return false; + } + + vshPrint(ctl, "%s\n", StorageVolPath); + VIR_FREE(StorageVolPath); virStorageVolFree(vol); return true; }