virsh: Add wrapper for virNWFilterFree

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:18:17 +02:00
parent 40a3a5b608
commit d39bd3998e
5 changed files with 26 additions and 17 deletions

View File

@ -868,7 +868,7 @@ sc_gettext_init:
$(_sc_search_regexp) $(_sc_search_regexp)
sc_prohibit_obj_free_apis_in_virsh: sc_prohibit_obj_free_apis_in_virsh:
@prohibit='\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|Secret|StoragePool|StorageVol)Free\b' \ @prohibit='\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|NWFilter|Secret|StoragePool|StorageVol)Free\b' \
in_vc_files='virsh.*\.[ch]$$' \ in_vc_files='virsh.*\.[ch]$$' \
exclude='sc_prohibit_obj_free_apis_in_virsh' \ exclude='sc_prohibit_obj_free_apis_in_virsh' \
halt='avoid using public virXXXFree in virsh, use virsh-prefixed wrappers instead' \ halt='avoid using public virXXXFree in virsh, use virsh-prefixed wrappers instead' \

View File

@ -21,6 +21,7 @@
#include <config.h> #include <config.h>
#include "virsh-completer-nwfilter.h" #include "virsh-completer-nwfilter.h"
#include "virsh-util.h"
#include "viralloc.h" #include "viralloc.h"
#include "virsh.h" #include "virsh.h"
#include "virstring.h" #include "virstring.h"
@ -56,7 +57,7 @@ virshNWFilterNameCompleter(vshControl *ctl,
ret = g_steal_pointer(&tmp); ret = g_steal_pointer(&tmp);
for (i = 0; i < nnwfilters; i++) for (i = 0; i < nnwfilters; i++)
virNWFilterFree(nwfilters[i]); virshNWFilterFree(nwfilters[i]);
g_free(nwfilters); g_free(nwfilters);
return ret; return ret;
} }

View File

@ -20,6 +20,7 @@
#include <config.h> #include <config.h>
#include "virsh-nwfilter.h" #include "virsh-nwfilter.h"
#include "virsh-util.h"
#include "internal.h" #include "internal.h"
#include "viralloc.h" #include "viralloc.h"
@ -91,7 +92,7 @@ static const vshCmdOptDef opts_nwfilter_define[] = {
static bool static bool
cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd) cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
{ {
virNWFilterPtr nwfilter; g_autoptr(virshNWFilter) nwfilter = NULL;
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
g_autofree char *buffer = NULL; g_autofree char *buffer = NULL;
@ -115,7 +116,6 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
if (nwfilter != NULL) { if (nwfilter != NULL) {
vshPrintExtra(ctl, _("Network filter %s defined from %s\n"), vshPrintExtra(ctl, _("Network filter %s defined from %s\n"),
virNWFilterGetName(nwfilter), from); virNWFilterGetName(nwfilter), from);
virNWFilterFree(nwfilter);
} else { } else {
vshError(ctl, _("Failed to define network filter from %s"), from); vshError(ctl, _("Failed to define network filter from %s"), from);
ret = false; ret = false;
@ -149,7 +149,7 @@ static const vshCmdOptDef opts_nwfilter_undefine[] = {
static bool static bool
cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd) cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd)
{ {
virNWFilterPtr nwfilter; g_autoptr(virshNWFilter) nwfilter = NULL;
bool ret = true; bool ret = true;
const char *name; const char *name;
@ -163,7 +163,6 @@ cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd)
ret = false; ret = false;
} }
virNWFilterFree(nwfilter);
return ret; return ret;
} }
@ -193,7 +192,7 @@ static const vshCmdOptDef opts_nwfilter_dumpxml[] = {
static bool static bool
cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd) cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
{ {
virNWFilterPtr nwfilter; g_autoptr(virshNWFilter) nwfilter = NULL;
bool ret = true; bool ret = true;
g_autofree char *dump = NULL; g_autofree char *dump = NULL;
@ -207,7 +206,6 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
ret = false; ret = false;
} }
virNWFilterFree(nwfilter);
return ret; return ret;
} }
@ -239,8 +237,7 @@ virshNWFilterListFree(struct virshNWFilterList *list)
if (list && list->filters) { if (list && list->filters) {
for (i = 0; i < list->nfilters; i++) { for (i = 0; i < list->nfilters; i++) {
if (list->filters[i]) virshNWFilterFree(list->filters[i]);
virNWFilterFree(list->filters[i]);
} }
g_free(list->filters); g_free(list->filters);
} }
@ -418,8 +415,8 @@ static bool
cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd) cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
{ {
bool ret = false; bool ret = false;
virNWFilterPtr nwfilter = NULL; g_autoptr(virshNWFilter) nwfilter = NULL;
virNWFilterPtr nwfilter_edited = NULL; g_autoptr(virshNWFilter) nwfilter_edited = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL); nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL);
@ -445,11 +442,6 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
if (nwfilter)
virNWFilterFree(nwfilter);
if (nwfilter_edited)
virNWFilterFree(nwfilter_edited);
return ret; return ret;
} }

View File

@ -318,6 +318,17 @@ virshNodeDeviceFree(virNodeDevicePtr device)
} }
void
virshNWFilterFree(virNWFilterPtr nwfilter)
{
if (!nwfilter)
return;
vshSaveLibvirtHelperError();
virNWFilterFree(nwfilter); /* sc_prohibit_obj_free_apis_in_virsh */
}
void void
virshSecretFree(virSecretPtr secret) virshSecretFree(virSecretPtr secret)
{ {

View File

@ -69,6 +69,11 @@ void
virshNodeDeviceFree(virNodeDevicePtr device); virshNodeDeviceFree(virNodeDevicePtr device);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNodeDevice, virshNodeDeviceFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNodeDevice, virshNodeDeviceFree);
typedef virNWFilter virshNWFilter;
void
virshNWFilterFree(virNWFilterPtr nwfilter);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNWFilter, virshNWFilterFree);
typedef virSecret virshSecret; typedef virSecret virshSecret;
void void
virshSecretFree(virSecretPtr secret); virshSecretFree(virSecretPtr secret);