1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-10 05:17:59 +03:00

virsh: Work around virSecretFree quirks

Similarly to other libvirt object freeing APIs the function resets the
libvirt error when called and doesn't take NULL gracefully. Install the
workaround and g_autoptr handlers similarly to the 'virshDomain' type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Peter Krempa 2020-01-24 15:24:49 +01:00
parent 374908e481
commit 7e8ed7d782
5 changed files with 29 additions and 14 deletions

View File

@ -1118,7 +1118,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)Free\b' \ @prohibit='\bvir(Domain|DomainSnapshot|Secret)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 virDomain(Snapshot)Free in virsh, use virsh-prefixed wrappers instead' \ halt='avoid using virDomain(Snapshot)Free in virsh, use virsh-prefixed wrappers instead' \

View File

@ -23,6 +23,7 @@
#include "virsh-completer-secret.h" #include "virsh-completer-secret.h"
#include "viralloc.h" #include "viralloc.h"
#include "virsh-secret.h" #include "virsh-secret.h"
#include "virsh-util.h"
#include "virsh.h" #include "virsh.h"
#include "virstring.h" #include "virstring.h"
@ -61,7 +62,7 @@ virshSecretUUIDCompleter(vshControl *ctl,
cleanup: cleanup:
for (i = 0; i < nsecrets; i++) for (i = 0; i < nsecrets; i++)
virSecretFree(secrets[i]); virshSecretFree(secrets[i]);
VIR_FREE(secrets); VIR_FREE(secrets);
return ret; return ret;
} }

View File

@ -20,6 +20,7 @@
#include <config.h> #include <config.h>
#include "virsh-secret.h" #include "virsh-secret.h"
#include "virsh-util.h"
#include "internal.h" #include "internal.h"
#include "virbuffer.h" #include "virbuffer.h"
@ -106,8 +107,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
VIR_FREE(buffer); VIR_FREE(buffer);
if (res) virshSecretFree(res);
virSecretFree(res);
return ret; return ret;
} }
@ -153,7 +153,7 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
virSecretFree(secret); virshSecretFree(secret);
return ret; return ret;
} }
@ -215,7 +215,7 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
virSecretFree(secret); virshSecretFree(secret);
return ret; return ret;
} }
@ -266,7 +266,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
VIR_DISPOSE_N(value, value_size); VIR_DISPOSE_N(value, value_size);
virSecretFree(secret); virshSecretFree(secret);
return ret; return ret;
} }
@ -312,7 +312,7 @@ cmdSecretUndefine(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
virSecretFree(secret); virshSecretFree(secret);
return ret; return ret;
} }
@ -348,10 +348,9 @@ virshSecretListFree(virshSecretListPtr list)
size_t i; size_t i;
if (list && list->secrets) { if (list && list->secrets) {
for (i = 0; i < list->nsecrets; i++) { for (i = 0; i < list->nsecrets; i++)
if (list->secrets[i]) virshSecretFree(list->secrets[i]);
virSecretFree(list->secrets[i]);
}
VIR_FREE(list->secrets); VIR_FREE(list->secrets);
} }
VIR_FREE(list); VIR_FREE(list);
@ -763,8 +762,7 @@ cmdSecretEvent(vshControl *ctl, const vshCmd *cmd)
if (eventId >= 0 && if (eventId >= 0 &&
virConnectSecretEventDeregisterAny(priv->conn, eventId) < 0) virConnectSecretEventDeregisterAny(priv->conn, eventId) < 0)
ret = false; ret = false;
if (secret) virshSecretFree(secret);
virSecretFree(secret);
return ret; return ret;
} }

View File

@ -250,6 +250,17 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap)
} }
void
virshSecretFree(virSecretPtr secret)
{
if (!secret)
return;
vshSaveLibvirtHelperError();
virSecretFree(secret); /* sc_prohibit_obj_free_apis_in_virsh */
}
int int
virshDomainGetXMLFromDom(vshControl *ctl, virshDomainGetXMLFromDom(vshControl *ctl,
virDomainPtr dom, virDomainPtr dom,

View File

@ -45,6 +45,11 @@ void
virshDomainFree(virDomainPtr dom); virshDomainFree(virDomainPtr dom);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshDomain, virshDomainFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshDomain, virshDomainFree);
typedef virSecret virshSecret;
void
virshSecretFree(virSecretPtr secret);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshSecret, virshSecretFree);
void void
virshDomainCheckpointFree(virDomainCheckpointPtr chk); virshDomainCheckpointFree(virDomainCheckpointPtr chk);