提交 439eb82e 编写于 作者: M Michal Privoznik

virchrdev: Use more g_autofree and VIR_AUTOCLOSE

Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 15b82112
...@@ -67,9 +67,9 @@ struct _virChrdevStreamInfo { ...@@ -67,9 +67,9 @@ struct _virChrdevStreamInfo {
*/ */
static char *virChrdevLockFilePath(const char *dev) static char *virChrdevLockFilePath(const char *dev)
{ {
char *path = NULL; g_autofree char *path = NULL;
char *sanitizedPath = NULL; g_autofree char *sanitizedPath = NULL;
char *devCopy; g_autofree char *devCopy = NULL;
char *filename; char *filename;
char *p; char *p;
...@@ -92,10 +92,7 @@ static char *virChrdevLockFilePath(const char *dev) ...@@ -92,10 +92,7 @@ static char *virChrdevLockFilePath(const char *dev)
sanitizedPath = virFileSanitizePath(path); sanitizedPath = virFileSanitizePath(path);
VIR_FREE(path); return g_steal_pointer(&sanitizedPath);
VIR_FREE(devCopy);
return sanitizedPath;
} }
/** /**
...@@ -107,10 +104,10 @@ static char *virChrdevLockFilePath(const char *dev) ...@@ -107,10 +104,10 @@ static char *virChrdevLockFilePath(const char *dev)
*/ */
static int virChrdevLockFileCreate(const char *dev) static int virChrdevLockFileCreate(const char *dev)
{ {
char *path = NULL; g_autofree char *path = NULL;
int ret = -1; int ret = -1;
int lockfd = -1; g_autofree char *pidStr = NULL;
char *pidStr = NULL; VIR_AUTOCLOSE lockfd = -1;
pid_t pid; pid_t pid;
/* build lock file path */ /* build lock file path */
...@@ -161,7 +158,6 @@ static int virChrdevLockFileCreate(const char *dev) ...@@ -161,7 +158,6 @@ static int virChrdevLockFileCreate(const char *dev)
_("Couldn't write to lock file for " _("Couldn't write to lock file for "
"device '%s' in path '%s'"), "device '%s' in path '%s'"),
dev, path); dev, path);
VIR_FORCE_CLOSE(lockfd);
unlink(path); unlink(path);
goto cleanup; goto cleanup;
} }
...@@ -170,9 +166,6 @@ static int virChrdevLockFileCreate(const char *dev) ...@@ -170,9 +166,6 @@ static int virChrdevLockFileCreate(const char *dev)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FORCE_CLOSE(lockfd);
VIR_FREE(path);
VIR_FREE(pidStr);
return ret; return ret;
} }
...@@ -184,10 +177,8 @@ static int virChrdevLockFileCreate(const char *dev) ...@@ -184,10 +177,8 @@ static int virChrdevLockFileCreate(const char *dev)
*/ */
static void virChrdevLockFileRemove(const char *dev) static void virChrdevLockFileRemove(const char *dev)
{ {
char *path = virChrdevLockFilePath(dev); g_autofree char *path = virChrdevLockFilePath(dev);
if (path) unlink(path);
unlink(path);
VIR_FREE(path);
} }
#else /* #ifdef VIR_CHRDEV_LOCK_FILE_PATH */ #else /* #ifdef VIR_CHRDEV_LOCK_FILE_PATH */
/* file locking for character devices is disabled */ /* file locking for character devices is disabled */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册