virConf *
virConfReadFile(const char *filename, unsigned int flags)
{
- char *content;
+ g_autofree char *content = NULL;
int len;
virConf *conf;
conf = virConfParse(filename, content, len, flags);
- VIR_FREE(content);
-
return conf;
}
virConfEntry *cur;
int ret;
int fd;
- char *content;
+ g_autofree char *content = NULL;
unsigned int use;
if (conf == NULL)
use = virBufferUse(&buf);
content = virBufferContentAndReset(&buf);
ret = safewrite(fd, content, use);
- VIR_FREE(content);
VIR_FORCE_CLOSE(fd);
if (ret != (int)use) {
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content"));
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virConfEntry *cur;
- char *content;
+ g_autofree char *content = NULL;
unsigned int use;
if ((memory == NULL) || (len == NULL) || (*len <= 0) || (conf == NULL))
if ((int)use >= *len) {
*len = (int)use;
- VIR_FREE(content);
return -1;
}
memcpy(memory, content, use);
- VIR_FREE(content);
*len = use;
return use;
}
int
virConfLoadConfig(virConf **conf, const char *name)
{
- char *path = NULL;
- int ret = -1;
+ g_autofree char *path = NULL;
*conf = NULL;
if (!(path = virConfLoadConfigPath(name)))
- goto cleanup;
+ return -1;
if (!virFileExists(path)) {
- ret = 0;
- goto cleanup;
+ return 0;
}
VIR_DEBUG("Loading config file '%s'", path);
if (!(*conf = virConfReadFile(path, 0)))
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- VIR_FREE(path);
- return ret;
+ return 0;
}