qemusecuritymock: Introduce and use freePaths()

Problem with current approach is that if
qemuSecuritySetAllLabel() fails, then the @chown_paths and
@xattr_paths hash tables are not freed and preserve values
already stored there into the next test case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Michal Privoznik 2019-04-15 16:15:10 +02:00
parent 80cf6ec6f2
commit 8ffb5f2738
3 changed files with 15 additions and 2 deletions

View File

@ -411,13 +411,23 @@ int checkPaths(void)
ret = 0; ret = 0;
cleanup: cleanup:
virHashRemoveAll(chown_paths);
virHashRemoveAll(xattr_paths);
virMutexUnlock(&m); virMutexUnlock(&m);
return ret; return ret;
} }
void freePaths(void)
{
virMutexLock(&m);
init_hash();
virHashFree(chown_paths);
virHashFree(xattr_paths);
chown_paths = xattr_paths = NULL;
virMutexUnlock(&m);
}
int int
virProcessRunInFork(virProcessForkCallback cb, virProcessRunInFork(virProcessForkCallback cb,
void *opaque) void *opaque)

View File

@ -125,6 +125,7 @@ testDomain(const void *opaque)
unsetenv(ENVVAR); unsetenv(ENVVAR);
virObjectUnref(vm); virObjectUnref(vm);
virObjectUnref(securityManager); virObjectUnref(securityManager);
freePaths();
return ret; return ret;
} }

View File

@ -21,3 +21,5 @@
#define ENVVAR "LIBVIRT_QEMU_SECURITY_TEST" #define ENVVAR "LIBVIRT_QEMU_SECURITY_TEST"
extern int checkPaths(void); extern int checkPaths(void);
extern void freePaths(void);