Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx> --- src/conf/virchrdev.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index a95b8976ac..7acbfd7f6a 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -326,6 +326,7 @@ int virChrdevOpen(virChrdevs *devs, char *path; int ret; bool added = false; + vir_g_autoptr(virLockGuard) lock = NULL; switch (source->type) { case VIR_DOMAIN_CHR_TYPE_PTY: @@ -346,12 +347,11 @@ int virChrdevOpen(virChrdevs *devs, return -1; } - virMutexLock(&devs->lock); + lock = virLockGuardNew(&devs->lock); if ((ent = virHashLookup(devs->hash, path))) { if (!force) { /* entry found, device is busy */ - virMutexUnlock(&devs->lock); return 1; } else { /* terminate existing connection */ @@ -369,16 +369,12 @@ int virChrdevOpen(virChrdevs *devs, } /* create the lock file */ - if ((ret = virChrdevLockFileCreate(path)) < 0) { - virMutexUnlock(&devs->lock); + if ((ret = virChrdevLockFileCreate(path)) < 0) return ret; - } /* obtain a reference to the stream */ - if (virStreamRef(st) < 0) { - virMutexUnlock(&devs->lock); + if (virStreamRef(st) < 0) return -1; - } cbdata = g_new0(virChrdevStreamInfo, 1); ent = g_new0(virChrdevHashEntry, 1); @@ -417,7 +413,6 @@ int virChrdevOpen(virChrdevs *devs, cbdata, virChrdevFDStreamCloseCbFree); - virMutexUnlock(&devs->lock); return 0; error: @@ -429,7 +424,6 @@ int virChrdevOpen(virChrdevs *devs, if (cbdata) VIR_FREE(cbdata->path); VIR_FREE(cbdata); - virMutexUnlock(&devs->lock); virChrdevHashEntryFree(ent); return -1; } -- 2.31.1