tests: use VIR_AUTOCLOSE

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Ján Tomko 2021-09-04 20:45:22 +02:00
parent ca24cb1e9b
commit e4756024ee
6 changed files with 8 additions and 19 deletions

View File

@ -38,7 +38,7 @@ VIR_LOG_INIT("tests.fdstreamtest");
static int testFDStreamReadCommon(const char *scratchdir, bool blocking) static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
{ {
int fd = -1; VIR_AUTOCLOSE fd = -1;
g_autofree char *file = NULL; g_autofree char *file = NULL;
int ret = -1; int ret = -1;
g_autofree char *pattern = NULL; g_autofree char *pattern = NULL;
@ -144,7 +144,6 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
cleanup: cleanup:
if (st) if (st)
virStreamFree(st); virStreamFree(st);
VIR_FORCE_CLOSE(fd);
if (file != NULL) if (file != NULL)
unlink(file); unlink(file);
if (conn) if (conn)
@ -165,7 +164,7 @@ static int testFDStreamReadNonblock(const void *data)
static int testFDStreamWriteCommon(const char *scratchdir, bool blocking) static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
{ {
int fd = -1; VIR_AUTOCLOSE fd = -1;
g_autofree char *file = NULL; g_autofree char *file = NULL;
int ret = -1; int ret = -1;
g_autofree char *pattern = NULL; g_autofree char *pattern = NULL;
@ -284,7 +283,6 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
cleanup: cleanup:
if (st) if (st)
virStreamFree(st); virStreamFree(st);
VIR_FORCE_CLOSE(fd);
if (file != NULL) if (file != NULL)
unlink(file); unlink(file);
if (conn) if (conn)

View File

@ -71,7 +71,7 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
g_autofree char *link_path = NULL; g_autofree char *link_path = NULL;
char *spot; char *spot;
int ret = -1; int ret = -1;
int fd = -1; VIR_AUTOCLOSE fd = -1;
unique_id_path = g_strdup_printf("%s/devices/pci0000:00/%s/unique_id", unique_id_path = g_strdup_printf("%s/devices/pci0000:00/%s/unique_id",
fakesysfsdir, devicepath); fakesysfsdir, devicepath);
@ -136,7 +136,6 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FORCE_CLOSE(fd);
return ret; return ret;
} }

View File

@ -194,7 +194,7 @@ holesSupported(void)
{ {
off_t offsets[] = {EXTENT, EXTENT, EXTENT, -1}; off_t offsets[] = {EXTENT, EXTENT, EXTENT, -1};
off_t tmp; off_t tmp;
int fd; VIR_AUTOCLOSE fd = -1;
bool ret = false; bool ret = false;
if ((fd = makeSparseFile(offsets, true)) < 0) if ((fd = makeSparseFile(offsets, true)) < 0)
@ -229,7 +229,6 @@ holesSupported(void)
ret = true; ret = true;
cleanup: cleanup:
VIR_FORCE_CLOSE(fd);
return ret; return ret;
} }
@ -261,7 +260,7 @@ static int
testFileInData(const void *opaque) testFileInData(const void *opaque)
{ {
const struct testFileInData *data = opaque; const struct testFileInData *data = opaque;
int fd = -1; VIR_AUTOCLOSE fd = -1;
int ret = -1; int ret = -1;
size_t i; size_t i;
@ -303,7 +302,6 @@ testFileInData(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FORCE_CLOSE(fd);
return ret; return ret;
} }

View File

@ -396,7 +396,7 @@ void testTLSWriteCertChain(const char *filename,
size_t ncerts) size_t ncerts)
{ {
size_t i; size_t i;
int fd; VIR_AUTOCLOSE fd = -1;
int err; int err;
static char buffer[1024*1024]; static char buffer[1024*1024];
size_t size; size_t size;
@ -420,8 +420,6 @@ void testTLSWriteCertChain(const char *filename,
abort(); abort();
} }
} }
VIR_FORCE_CLOSE(fd);
} }

View File

@ -177,7 +177,7 @@ make_file(const char *path,
const char *value, const char *value,
ssize_t len) ssize_t len)
{ {
int fd = -1; VIR_AUTOCLOSE fd = -1;
g_autofree char *filepath = NULL; g_autofree char *filepath = NULL;
if (value && len == -1) if (value && len == -1)
len = strlen(value); len = strlen(value);
@ -189,8 +189,6 @@ make_file(const char *path,
if (value && safewrite(fd, value, len) != len) if (value && safewrite(fd, value, len) != len)
ABORT("Unable to write: %s", filepath); ABORT("Unable to write: %s", filepath);
VIR_FORCE_CLOSE(fd);
} }
static void static void

View File

@ -125,7 +125,7 @@ static int testRotatingFileInitOne(const char *filename,
unlink(filename); unlink(filename);
} else { } else {
char buf[1024]; char buf[1024];
int fd; VIR_AUTOCLOSE fd = -1;
VIR_DEBUG("Creating %s size %zu", filename, (size_t)size); VIR_DEBUG("Creating %s size %zu", filename, (size_t)size);
@ -142,12 +142,10 @@ static int testRotatingFileInitOne(const char *filename,
if (safewrite(fd, buf, towrite) != towrite) { if (safewrite(fd, buf, towrite) != towrite) {
fprintf(stderr, "Cannot write to %s\n", filename); fprintf(stderr, "Cannot write to %s\n", filename);
VIR_FORCE_CLOSE(fd);
return -1; return -1;
} }
size -= towrite; size -= towrite;
} }
VIR_FORCE_CLOSE(fd);
} }
return 0; return 0;
} }