Once virNetServerProgramNew returns, the program objects have
either been added to the @srv or @srvAdm list increasing the
refcnt or there was an error. In either case, we can lower the
refcnt from virNetServerProgramNew and set the object to NULL
since it won't be used any more.
The @srv or @srvAdm dispose function (virNetServerDispose) will
handle the Unref of each object during the virHashFree when the
object is removed from the hash table.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
daemon/libvirtd.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 0afd1dd82..b47f875d9 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1352,7 +1352,11 @@ int main(int argc, char **argv) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (virNetServerAddProgram(srv, remoteProgram) < 0) {
+
+ rc = virNetServerAddProgram(srv, remoteProgram);
+ virObjectUnref(remoteProgram);
+ remoteProgram = NULL;
+ if (rc < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
@@ -1364,7 +1368,11 @@ int main(int argc, char **argv) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (virNetServerAddProgram(srv, lxcProgram) < 0) {
+
+ rc = virNetServerAddProgram(srv, lxcProgram);
+ virObjectUnref(lxcProgram);
+ lxcProgram = NULL;
+ if (rc < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
@@ -1376,7 +1384,11 @@ int main(int argc, char **argv) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (virNetServerAddProgram(srv, qemuProgram) < 0) {
+
+ rc = virNetServerAddProgram(srv, qemuProgram);
+ virObjectUnref(qemuProgram);
+ qemuProgram = NULL;
+ if (rc < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
@@ -1414,7 +1426,11 @@ int main(int argc, char **argv) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (virNetServerAddProgram(srvAdm, adminProgram) < 0) {
+
+ rc = virNetServerAddProgram(srvAdm, adminProgram);
+ virObjectUnref(adminProgram);
+ adminProgram = NULL;
+ if (rc < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
@@ -1524,10 +1540,6 @@ int main(int argc, char **argv) {
virStateCleanup();
}
- virObjectUnref(adminProgram);
- virObjectUnref(qemuProgram);
- virObjectUnref(lxcProgram);
- virObjectUnref(remoteProgram);
virObjectUnref(dmn);
virNetlinkShutdown();
--
2.13.6