Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
build-aux/syntax-check.mk | 2 +-
tools/virsh-console.c | 8 ++++----
tools/virsh-domain.c | 4 +---
tools/virsh-util.c | 12 ++++++++++++
tools/virsh-util.h | 5 +++++
tools/virsh-volume.c | 8 ++------
6 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index 5daf5afcd0..cb12b64532 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -868,7 +868,7 @@ sc_gettext_init:
$(_sc_search_regexp)
sc_prohibit_obj_free_apis_in_virsh:
- @prohibit='\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|NWFilter|Secret|StoragePool|StorageVol)Free\b'
\
+ @prohibit='\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|NWFilter|Secret|StoragePool|StorageVol|Stream)Free\b'
\
in_vc_files='virsh.*\.[ch]$$' \
exclude='sc_prohibit_obj_free_apis_in_virsh' \
halt='avoid using public virXXXFree in virsh, use virsh-prefixed wrappers
instead' \
diff --git a/tools/virsh-console.c b/tools/virsh-console.c
index 449619c95f..67ee608706 100644
--- a/tools/virsh-console.c
+++ b/tools/virsh-console.c
@@ -33,6 +33,7 @@
# include "internal.h"
# include "virsh.h"
# include "virsh-console.h"
+# include "virsh-util.h"
# include "virlog.h"
# include "virfile.h"
# include "viralloc.h"
@@ -117,8 +118,8 @@ virConsoleShutdown(virConsole *con,
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot terminate console stream"));
}
- virStreamFree(con->st);
- con->st = NULL;
+
+ g_clear_pointer(&con->st, virshStreamFree);
}
VIR_FREE(con->streamToTerminal.data);
VIR_FREE(con->terminalToStream.data);
@@ -140,8 +141,7 @@ virConsoleDispose(void *obj)
{
virConsole *con = obj;
- if (con->st)
- virStreamFree(con->st);
+ virshStreamFree(con->st);
virCondDestroy(&con->cond);
virResetError(&con->error);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index b1943b3875..0d4f7cc407 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5540,7 +5540,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
const char *name = NULL;
char *file = NULL;
int fd = -1;
- virStreamPtr st = NULL;
+ g_autoptr(virshStream) st = NULL;
unsigned int screen = 0;
unsigned int flags = 0; /* currently unused */
bool ret = false;
@@ -5610,8 +5610,6 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
unlink(file);
if (generated)
VIR_FREE(file);
- if (st)
- virStreamFree(st);
VIR_FORCE_CLOSE(fd);
VIR_FREE(mime);
return ret;
diff --git a/tools/virsh-util.c b/tools/virsh-util.c
index fc2839d8fc..8fb617fa3c 100644
--- a/tools/virsh-util.c
+++ b/tools/virsh-util.c
@@ -362,6 +362,18 @@ virshStorageVolFree(virStorageVolPtr vol)
}
+
+void
+virshStreamFree(virStreamPtr stream)
+{
+ if (!stream)
+ return;
+
+ vshSaveLibvirtHelperError();
+ virStreamFree(stream); /* sc_prohibit_obj_free_apis_in_virsh */
+}
+
+
int
virshDomainGetXMLFromDom(vshControl *ctl,
virDomainPtr dom,
diff --git a/tools/virsh-util.h b/tools/virsh-util.h
index 065055ddb1..838935d5e8 100644
--- a/tools/virsh-util.h
+++ b/tools/virsh-util.h
@@ -89,6 +89,11 @@ void
virshStorageVolFree(virStorageVolPtr vol);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStorageVol, virshStorageVolFree);
+typedef virStream virshStream;
+void
+virshStreamFree(virStreamPtr stream);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStream, virshStreamFree);
+
int
virshDomainState(vshControl *ctl,
virDomainPtr dom,
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index b896ebbbf9..70b6eac687 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -656,7 +656,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshStorageVol) vol = NULL;
bool ret = false;
int fd = -1;
- virStreamPtr st = NULL;
+ g_autoptr(virshStream) st = NULL;
const char *name = NULL;
unsigned long long offset = 0, length = 0;
virshControl *priv = ctl->privData;
@@ -731,8 +731,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
ret = true;
cleanup:
- if (st)
- virStreamFree(st);
VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -776,7 +774,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshStorageVol) vol = NULL;
bool ret = false;
int fd = -1;
- virStreamPtr st = NULL;
+ g_autoptr(virshStream) st = NULL;
const char *name = NULL;
unsigned long long offset = 0, length = 0;
bool created = false;
@@ -851,8 +849,6 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
VIR_FORCE_CLOSE(fd);
if (!ret && created)
unlink(file);
- if (st)
- virStreamFree(st);
return ret;
}
--
2.32.0