qemuNamespaceUnlinkPaths: Fix wrong use of iterator variable

'i' is used in both outer and inner loop. Since 'devMountsPath' is now a
NULL-terminated list, we can use a GStrv to iterate it;

Additionally rewrite the conditional of adding to the 'unlinkPaths'
array so that it's more clear what's happening.

Fixes: 5c86fbb72d
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-04 14:27:19 +01:00
parent 5ab8342e64
commit e310900e50

View File

@ -1362,14 +1362,20 @@ qemuNamespaceUnlinkPaths(virDomainObjPtr vm,
const char *file = paths[i];
if (STRPREFIX(file, QEMU_DEVPREFIX)) {
for (i = 0; i < ndevMountsPath; i++) {
if (STREQ(devMountsPath[i], "/dev"))
GStrv mount;
bool inSubmount = false;
for (mount = devMountsPath; *mount; mount++) {
if (STREQ(*mount, "/dev"))
continue;
if (STRPREFIX(file, devMountsPath[i]))
if (STRPREFIX(file, *mount)) {
inSubmount = true;
break;
}
}
if (i == ndevMountsPath &&
if (!inSubmount &&
virStringListAdd(&unlinkPaths, file) < 0)
return -1;
}