virsh: Add wrapper for virStreamFree

Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Michal Privoznik 2021-09-26 13:27:26 +02:00
parent d39bd3998e
commit f427e6c643
6 changed files with 25 additions and 14 deletions

View File

@ -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' \

View File

@ -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);

View File

@ -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;

View File

@ -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,

View File

@ -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,

View File

@ -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;
}