mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
lib: Prefer g_autoptr(dnsmasqCaps) instead of explicit unref
The dnsmasqCaps type has its own cleanup function defined and ready to use via g_autoptr(). Use automatic cleanup instead of an explicit one. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
parent
a7ffa2a647
commit
6944c78d38
@ -702,44 +702,42 @@ dnsmasqCapsRefreshInternal(dnsmasqCaps *caps, bool force)
|
|||||||
static dnsmasqCaps *
|
static dnsmasqCaps *
|
||||||
dnsmasqCapsNewEmpty(void)
|
dnsmasqCapsNewEmpty(void)
|
||||||
{
|
{
|
||||||
dnsmasqCaps *caps;
|
g_autoptr(dnsmasqCaps) caps = NULL;
|
||||||
|
|
||||||
if (dnsmasqCapsInitialize() < 0)
|
if (dnsmasqCapsInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(caps = virObjectNew(dnsmasqCapsClass)))
|
if (!(caps = virObjectNew(dnsmasqCapsClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
caps->binaryPath = g_strdup(DNSMASQ);
|
caps->binaryPath = g_strdup(DNSMASQ);
|
||||||
return caps;
|
return g_steal_pointer(&caps);
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsmasqCaps *
|
dnsmasqCaps *
|
||||||
dnsmasqCapsNewFromBuffer(const char *buf)
|
dnsmasqCapsNewFromBuffer(const char *buf)
|
||||||
{
|
{
|
||||||
dnsmasqCaps *caps = dnsmasqCapsNewEmpty();
|
g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty();
|
||||||
|
|
||||||
if (!caps)
|
if (!caps)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (dnsmasqCapsSetFromBuffer(caps, buf) < 0) {
|
if (dnsmasqCapsSetFromBuffer(caps, buf) < 0)
|
||||||
virObjectUnref(caps);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
return caps;
|
return g_steal_pointer(&caps);
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsmasqCaps *
|
dnsmasqCaps *
|
||||||
dnsmasqCapsNewFromBinary(void)
|
dnsmasqCapsNewFromBinary(void)
|
||||||
{
|
{
|
||||||
dnsmasqCaps *caps = dnsmasqCapsNewEmpty();
|
g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty();
|
||||||
|
|
||||||
if (!caps)
|
if (!caps)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (dnsmasqCapsRefreshInternal(caps, true) < 0) {
|
if (dnsmasqCapsRefreshInternal(caps, true) < 0)
|
||||||
virObjectUnref(caps);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
return caps;
|
return g_steal_pointer(&caps);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -112,8 +112,9 @@ static int
|
|||||||
mymain(void)
|
mymain(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
dnsmasqCaps *full
|
g_autoptr(dnsmasqCaps) full = NULL;
|
||||||
= dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67\n--bind-dynamic\n--ra-param");
|
|
||||||
|
full = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67\n--bind-dynamic\n--ra-param");
|
||||||
|
|
||||||
#define DO_TEST(xname, xcaps) \
|
#define DO_TEST(xname, xcaps) \
|
||||||
do { \
|
do { \
|
||||||
@ -154,8 +155,6 @@ mymain(void)
|
|||||||
DO_TEST("leasetime-hours", full);
|
DO_TEST("leasetime-hours", full);
|
||||||
DO_TEST("leasetime-infinite", full);
|
DO_TEST("leasetime-infinite", full);
|
||||||
|
|
||||||
virObjectUnref(full);
|
|
||||||
|
|
||||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user