diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 4f5127cde7..bd6adcf365 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -168,16 +168,18 @@ virIdentityPtr virIdentityGetSystem(void) goto cleanup; #if WITH_SELINUX - if (getcon(&con) < 0) { - virReportSystemError(errno, "%s", - _("Unable to lookup SELinux process context")); - goto cleanup; - } - if (VIR_STRDUP(seccontext, con) < 0) { + if (is_selinux_enabled()) { + if (getcon(&con) < 0) { + virReportSystemError(errno, "%s", + _("Unable to lookup SELinux process context")); + goto cleanup; + } + if (VIR_STRDUP(seccontext, con) < 0) { + freecon(con); + goto cleanup; + } freecon(con); - goto cleanup; } - freecon(con); #endif if (!(ret = virIdentityNew()))