mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +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:
parent
374908e481
commit
7e8ed7d782
@ -1118,7 +1118,7 @@ sc_gettext_init:
|
||||
$(_sc_search_regexp)
|
||||
|
||||
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]$$' \
|
||||
exclude='sc_prohibit_obj_free_apis_in_virsh' \
|
||||
halt='avoid using virDomain(Snapshot)Free in virsh, use virsh-prefixed wrappers instead' \
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "virsh-completer-secret.h"
|
||||
#include "viralloc.h"
|
||||
#include "virsh-secret.h"
|
||||
#include "virsh-util.h"
|
||||
#include "virsh.h"
|
||||
#include "virstring.h"
|
||||
|
||||
@ -61,7 +62,7 @@ virshSecretUUIDCompleter(vshControl *ctl,
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < nsecrets; i++)
|
||||
virSecretFree(secrets[i]);
|
||||
virshSecretFree(secrets[i]);
|
||||
VIR_FREE(secrets);
|
||||
return ret;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <config.h>
|
||||
#include "virsh-secret.h"
|
||||
#include "virsh-util.h"
|
||||
|
||||
#include "internal.h"
|
||||
#include "virbuffer.h"
|
||||
@ -106,8 +107,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(buffer);
|
||||
if (res)
|
||||
virSecretFree(res);
|
||||
virshSecretFree(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd)
|
||||
ret = true;
|
||||
|
||||
cleanup:
|
||||
virSecretFree(secret);
|
||||
virshSecretFree(secret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
|
||||
ret = true;
|
||||
|
||||
cleanup:
|
||||
virSecretFree(secret);
|
||||
virshSecretFree(secret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -266,7 +266,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
cleanup:
|
||||
VIR_DISPOSE_N(value, value_size);
|
||||
virSecretFree(secret);
|
||||
virshSecretFree(secret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -312,7 +312,7 @@ cmdSecretUndefine(vshControl *ctl, const vshCmd *cmd)
|
||||
ret = true;
|
||||
|
||||
cleanup:
|
||||
virSecretFree(secret);
|
||||
virshSecretFree(secret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -348,10 +348,9 @@ virshSecretListFree(virshSecretListPtr list)
|
||||
size_t i;
|
||||
|
||||
if (list && list->secrets) {
|
||||
for (i = 0; i < list->nsecrets; i++) {
|
||||
if (list->secrets[i])
|
||||
virSecretFree(list->secrets[i]);
|
||||
}
|
||||
for (i = 0; i < list->nsecrets; i++)
|
||||
virshSecretFree(list->secrets[i]);
|
||||
|
||||
VIR_FREE(list->secrets);
|
||||
}
|
||||
VIR_FREE(list);
|
||||
@ -763,8 +762,7 @@ cmdSecretEvent(vshControl *ctl, const vshCmd *cmd)
|
||||
if (eventId >= 0 &&
|
||||
virConnectSecretEventDeregisterAny(priv->conn, eventId) < 0)
|
||||
ret = false;
|
||||
if (secret)
|
||||
virSecretFree(secret);
|
||||
virshSecretFree(secret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
virshDomainGetXMLFromDom(vshControl *ctl,
|
||||
virDomainPtr dom,
|
||||
|
@ -45,6 +45,11 @@ void
|
||||
virshDomainFree(virDomainPtr dom);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshDomain, virshDomainFree);
|
||||
|
||||
typedef virSecret virshSecret;
|
||||
void
|
||||
virshSecretFree(virSecretPtr secret);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshSecret, virshSecretFree);
|
||||
|
||||
void
|
||||
virshDomainCheckpointFree(virDomainCheckpointPtr chk);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user