From 8ffb5f27384d73390c8b190eee2b0a40b4a4f3eb Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 15 Apr 2019 16:15:10 +0200 Subject: [PATCH] qemusecuritymock: Introduce and use freePaths() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Daniel P. Berrangé --- tests/qemusecuritymock.c | 14 ++++++++++++-- tests/qemusecuritytest.c | 1 + tests/qemusecuritytest.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index e52a41067a..815bd44d76 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -411,13 +411,23 @@ int checkPaths(void) ret = 0; cleanup: - virHashRemoveAll(chown_paths); - virHashRemoveAll(xattr_paths); virMutexUnlock(&m); return ret; } +void freePaths(void) +{ + virMutexLock(&m); + init_hash(); + + virHashFree(chown_paths); + virHashFree(xattr_paths); + chown_paths = xattr_paths = NULL; + virMutexUnlock(&m); +} + + int virProcessRunInFork(virProcessForkCallback cb, void *opaque) diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c index 79d4f744b6..9ac953f388 100644 --- a/tests/qemusecuritytest.c +++ b/tests/qemusecuritytest.c @@ -125,6 +125,7 @@ testDomain(const void *opaque) unsetenv(ENVVAR); virObjectUnref(vm); virObjectUnref(securityManager); + freePaths(); return ret; } diff --git a/tests/qemusecuritytest.h b/tests/qemusecuritytest.h index f166eac3ac..812d73f073 100644 --- a/tests/qemusecuritytest.h +++ b/tests/qemusecuritytest.h @@ -21,3 +21,5 @@ #define ENVVAR "LIBVIRT_QEMU_SECURITY_TEST" extern int checkPaths(void); + +extern void freePaths(void);