vshStringToArray(const char *str,
char ***array)
{
- char *str_copied = g_strdup(str);
+ g_autofree char *str_copied = g_strdup(str);
char *str_tok = NULL;
char *tmp;
unsigned int nstr_tokens = 0;
arr[nstr_tokens++] = g_strdup(str_tok);
*array = arr;
- VIR_FREE(str_copied);
return nstr_tokens;
}
{
size_t i;
const vshCmdOptDef *ret = NULL;
- char *alias = NULL;
+ g_autofree char *alias = NULL;
if (STREQ(name, helpopt.name))
return &helpopt;
cmd->name, name);
}
cleanup:
- VIR_FREE(alias);
return ret;
}
vshDebug(vshControl *ctl, int level, const char *format, ...)
{
va_list ap;
- char *str;
+ g_autofree char *str = NULL;
/* Aligning log levels to that of libvirt.
* Traces with levels >= user-specified-level
str = g_strdup_vprintf(format, ap);
va_end(ap);
fputs(str, stdout);
- VIR_FREE(str);
}
void
vshPrintExtra(vshControl *ctl, const char *format, ...)
{
va_list ap;
- char *str;
+ g_autofree char *str = NULL;
if (ctl && ctl->quiet)
return;
str = g_strdup_vprintf(format, ap);
va_end(ap);
fputs(str, stdout);
- VIR_FREE(str);
}
vshPrint(vshControl *ctl G_GNUC_UNUSED, const char *format, ...)
{
va_list ap;
- char *str;
+ g_autofree char *str = NULL;
va_start(ap, format);
str = g_strdup_vprintf(format, ap);
va_end(ap);
fputs(str, stdout);
- VIR_FREE(str);
}
vshError(vshControl *ctl, const char *format, ...)
{
va_list ap;
- char *str;
+ g_autofree char *str = NULL;
if (ctl != NULL) {
va_start(ap, format);
fprintf(stderr, "%s\n", NULLSTR(str));
fflush(stderr);
- VIR_FREE(str);
}
va_list ap)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
- char *str = NULL;
+ g_autofree char *str = NULL;
size_t len;
const char *lvl = "";
g_autoptr(GDateTime) now = g_date_time_new_now_local();
if (safewrite(ctl->log_fd, str, len) < 0)
goto error;
- VIR_FREE(str);
return;
error:
vshCloseLogFile(ctl);
vshError(ctl, "%s", _("failed to write the log file"));
- VIR_FREE(str);
}
/**
char *
vshEditWriteToTempFile(vshControl *ctl, const char *doc)
{
- char *ret;
+ g_autofree char *ret = NULL;
const char *tmpdir;
int fd;
if (fd == -1) {
vshError(ctl, _("g_mkstemp_full: failed to create temporary file: %s"),
g_strerror(errno));
- VIR_FREE(ret);
return NULL;
}
ret, g_strerror(errno));
VIR_FORCE_CLOSE(fd);
unlink(ret);
- VIR_FREE(ret);
return NULL;
}
if (VIR_CLOSE(fd) < 0) {
vshError(ctl, _("close: %s: failed to write or close temporary file: %s"),
ret, g_strerror(errno));
unlink(ret);
- VIR_FREE(ret);
return NULL;
}
vshEditFile(vshControl *ctl, const char *filename)
{
const char *editor;
- virCommand *cmd;
+ g_autoptr(virCommand) cmd = NULL;
int ret = -1;
int outfd = STDOUT_FILENO;
int errfd = STDERR_FILENO;
ret = 0;
cleanup:
- virCommandFree(cmd);
return ret;
}
static int
vshReadlineInit(vshControl *ctl)
{
- char *userdir = NULL;
+ g_autofree char *userdir = NULL;
int max_history = 500;
int ret = -1;
- char *histsize_env = NULL;
+ g_autofree char *histsize_env = NULL;
const char *histsize_str = NULL;
const char *break_characters = " \t\n`@$><=;|&{(";
const char *quote_characters = "\"'";
ret = 0;
cleanup:
- VIR_FREE(userdir);
- VIR_FREE(histsize_env);
return ret;
}
vshInitDebug(vshControl *ctl)
{
const char *debugEnv;
- char *env = NULL;
if (ctl->debug == VSH_DEBUG_DEFAULT) {
- env = g_strdup_printf("%s_DEBUG", ctl->env_prefix);
+ g_autofree char *env = g_strdup_printf("%s_DEBUG", ctl->env_prefix);
/* log level not set from commandline, check env variable */
debugEnv = getenv(env);
ctl->debug = debug;
}
}
- VIR_FREE(env);
}
if (ctl->logfile == NULL) {
- env = g_strdup_printf("%s_LOG_FILE", ctl->env_prefix);
+ g_autofree char *env = g_strdup_printf("%s_LOG_FILE", ctl->env_prefix);
/* log file not set from cmdline */
debugEnv = getenv(env);
ctl->logfile = g_strdup(debugEnv);
vshOpenLogFile(ctl);
}
- VIR_FREE(env);
}
return 0;
bool err = false;
int count = 0;
const vshCmdOpt *opt = NULL;
- char *arg;
+ g_autofree char *arg = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (vshCommandOptBool(cmd, "shell"))
err = true;
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
- char *str;
+ g_autofree char *str = NULL;
g_auto(virBuffer) xmlbuf = VIR_BUFFER_INITIALIZER;
const char *curr = opt->data;
else
virBufferAdd(&buf, str, -1);
count++;
- VIR_FREE(str);
}
arg = virBufferContentAndReset(&buf);
else
vshPrint(ctl, "%s", arg);
}
- VIR_FREE(arg);
return true;
}