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(a)redhat.com>
---
src/util/virdnsmasq.c | 18 ++++++++----------
tests/networkxml2conftest.c | 7 +++----
2 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index d304929d51..f4bdab116e 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -715,31 +715,29 @@ dnsmasqCapsNewEmpty(void)
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 *
diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c
index 178c74d9af..d79c2b4783 100644
--- a/tests/networkxml2conftest.c
+++ b/tests/networkxml2conftest.c
@@ -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;
}
--
2.34.1