mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15: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 *
|
||||
dnsmasqCapsNewEmpty(void)
|
||||
{
|
||||
dnsmasqCaps *caps;
|
||||
g_autoptr(dnsmasqCaps) caps = NULL;
|
||||
|
||||
if (dnsmasqCapsInitialize() < 0)
|
||||
return NULL;
|
||||
if (!(caps = virObjectNew(dnsmasqCapsClass)))
|
||||
return NULL;
|
||||
caps->binaryPath = g_strdup(DNSMASQ);
|
||||
return caps;
|
||||
return g_steal_pointer(&caps);
|
||||
}
|
||||
|
||||
dnsmasqCaps *
|
||||
dnsmasqCapsNewFromBuffer(const char *buf)
|
||||
{
|
||||
dnsmasqCaps *caps = dnsmasqCapsNewEmpty();
|
||||
g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty();
|
||||
|
||||
if (!caps)
|
||||
return NULL;
|
||||
|
||||
if (dnsmasqCapsSetFromBuffer(caps, buf) < 0) {
|
||||
virObjectUnref(caps);
|
||||
if (dnsmasqCapsSetFromBuffer(caps, buf) < 0)
|
||||
return NULL;
|
||||
}
|
||||
return caps;
|
||||
|
||||
return g_steal_pointer(&caps);
|
||||
}
|
||||
|
||||
dnsmasqCaps *
|
||||
dnsmasqCapsNewFromBinary(void)
|
||||
{
|
||||
dnsmasqCaps *caps = dnsmasqCapsNewEmpty();
|
||||
g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty();
|
||||
|
||||
if (!caps)
|
||||
return NULL;
|
||||
|
||||
if (dnsmasqCapsRefreshInternal(caps, true) < 0) {
|
||||
virObjectUnref(caps);
|
||||
if (dnsmasqCapsRefreshInternal(caps, true) < 0)
|
||||
return NULL;
|
||||
}
|
||||
return caps;
|
||||
|
||||
return g_steal_pointer(&caps);
|
||||
}
|
||||
|
||||
const char *
|
||||
|
@ -112,8 +112,9 @@ static int
|
||||
mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
dnsmasqCaps *full
|
||||
= dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67\n--bind-dynamic\n--ra-param");
|
||||
g_autoptr(dnsmasqCaps) full = NULL;
|
||||
|
||||
full = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67\n--bind-dynamic\n--ra-param");
|
||||
|
||||
#define DO_TEST(xname, xcaps) \
|
||||
do { \
|
||||
@ -154,8 +155,6 @@ mymain(void)
|
||||
DO_TEST("leasetime-hours", full);
|
||||
DO_TEST("leasetime-infinite", full);
|
||||
|
||||
virObjectUnref(full);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user