mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
tests: schema: Simplify memory handling using g_autofree
Refactor various functions to avoid multiple freeing function calls. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
7a69486c4d
commit
5f5542b44e
@ -72,8 +72,6 @@ testSchemaDir(const char *schema,
|
|||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int rc;
|
int rc;
|
||||||
char *test_name = NULL;
|
|
||||||
char *xml_path = NULL;
|
|
||||||
struct testSchemaData data = {
|
struct testSchemaData data = {
|
||||||
.validator = validator,
|
.validator = validator,
|
||||||
};
|
};
|
||||||
@ -82,6 +80,9 @@ testSchemaDir(const char *schema,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
|
while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
|
||||||
|
g_autofree char *test_name = NULL;
|
||||||
|
g_autofree char *xml_path = NULL;
|
||||||
|
|
||||||
if (!virStringHasSuffix(ent->d_name, ".xml"))
|
if (!virStringHasSuffix(ent->d_name, ".xml"))
|
||||||
continue;
|
continue;
|
||||||
if (ent->d_name[0] == '.')
|
if (ent->d_name[0] == '.')
|
||||||
@ -94,16 +95,11 @@ testSchemaDir(const char *schema,
|
|||||||
data.xml_path = xml_path;
|
data.xml_path = xml_path;
|
||||||
if (virTestRun(test_name, testSchemaFile, &data) < 0)
|
if (virTestRun(test_name, testSchemaFile, &data) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
VIR_FREE(test_name);
|
|
||||||
VIR_FREE(xml_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
VIR_FREE(test_name);
|
|
||||||
VIR_FREE(xml_path);
|
|
||||||
VIR_DIR_CLOSE(dir);
|
VIR_DIR_CLOSE(dir);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -114,19 +110,16 @@ testSchemaDirs(const char *schema, virXMLValidatorPtr validator, ...)
|
|||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *dir_path = NULL;
|
|
||||||
const char *dir;
|
const char *dir;
|
||||||
|
|
||||||
va_start(args, validator);
|
va_start(args, validator);
|
||||||
|
|
||||||
while ((dir = va_arg(args, char *))) {
|
while ((dir = va_arg(args, char *))) {
|
||||||
dir_path = g_strdup_printf("%s/%s", abs_srcdir, dir);
|
g_autofree char *dir_path = g_strdup_printf("%s/%s", abs_srcdir, dir);
|
||||||
if (testSchemaDir(schema, validator, dir_path) < 0)
|
if (testSchemaDir(schema, validator, dir_path) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
VIR_FREE(dir_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(dir_path);
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -136,20 +129,15 @@ static int
|
|||||||
testSchemaGrammar(const void *opaque)
|
testSchemaGrammar(const void *opaque)
|
||||||
{
|
{
|
||||||
struct testSchemaData *data = (struct testSchemaData *) opaque;
|
struct testSchemaData *data = (struct testSchemaData *) opaque;
|
||||||
char *schema_path;
|
g_autofree char *schema_path = NULL;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
schema_path = g_strdup_printf("%s/docs/schemas/%s", abs_top_srcdir,
|
schema_path = g_strdup_printf("%s/docs/schemas/%s", abs_top_srcdir,
|
||||||
data->schema);
|
data->schema);
|
||||||
|
|
||||||
if (!(data->validator = virXMLValidatorInit(schema_path)))
|
if (!(data->validator = virXMLValidatorInit(schema_path)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(schema_path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user