virFileWrapper: Use VIR_AUTOFREE()

This enables us to simplify the code a bit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Michal Privoznik 2019-03-13 09:54:45 +01:00
parent 288e0ab106
commit 6e31c4b27e

View File

@ -152,110 +152,74 @@ virFileWrapperOverridePrefix(const char *path)
FILE *fopen(const char *path, const char *mode) FILE *fopen(const char *path, const char *mode)
{ {
FILE *ret = NULL; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_fopen(newpath, mode); return real_fopen(newpath, mode);
VIR_FREE(newpath);
return ret;
} }
int access(const char *path, int mode) int access(const char *path, int mode)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_access(newpath, mode); return real_access(newpath, mode);
VIR_FREE(newpath);
return ret;
} }
# ifdef HAVE___LXSTAT # ifdef HAVE___LXSTAT
int __lxstat(int ver, const char *path, struct stat *sb) int __lxstat(int ver, const char *path, struct stat *sb)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real___lxstat(ver, newpath, sb); return real___lxstat(ver, newpath, sb);
VIR_FREE(newpath);
return ret;
} }
# endif /* HAVE___LXSTAT */ # endif /* HAVE___LXSTAT */
int lstat(const char *path, struct stat *sb) int lstat(const char *path, struct stat *sb)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_lstat(newpath, sb); return real_lstat(newpath, sb);
VIR_FREE(newpath);
return ret;
} }
# ifdef HAVE___XSTAT # ifdef HAVE___XSTAT
int __xstat(int ver, const char *path, struct stat *sb) int __xstat(int ver, const char *path, struct stat *sb)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real___xstat(ver, newpath, sb); return real___xstat(ver, newpath, sb);
VIR_FREE(newpath);
return ret;
} }
# endif /* HAVE___XSTAT */ # endif /* HAVE___XSTAT */
int stat(const char *path, struct stat *sb) int stat(const char *path, struct stat *sb)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_stat(newpath, sb); return real_stat(newpath, sb);
VIR_FREE(newpath);
return ret;
} }
int mkdir(const char *path, mode_t mode) int mkdir(const char *path, mode_t mode)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_mkdir(newpath, mode); return real_mkdir(newpath, mode);
VIR_FREE(newpath);
return ret;
} }
int open(const char *path, int flags, ...) int open(const char *path, int flags, ...)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
va_list ap; va_list ap;
mode_t mode = 0; mode_t mode = 0;
@ -270,24 +234,15 @@ int open(const char *path, int flags, ...)
va_end(ap); va_end(ap);
} }
ret = real_open(newpath, flags, mode); return real_open(newpath, flags, mode);
VIR_FREE(newpath);
return ret;
} }
DIR *opendir(const char *path) DIR *opendir(const char *path)
{ {
DIR *ret = NULL; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_opendir(newpath); return real_opendir(newpath);
VIR_FREE(newpath);
return ret;
} }
#endif #endif