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>
---
src/remote/remote_daemon.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index f61d58f3e5..dee634d7e1 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -1317,7 +1317,10 @@ int main(int argc, char **argv) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (virNetServerAddProgram(srv, remoteProgram) < 0) {
+
+ rc = virNetServerAddProgram(srv, remoteProgram);
+ virObjectUnref(remoteProgram);
+ if (rc < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
@@ -1329,7 +1332,10 @@ int main(int argc, char **argv) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (virNetServerAddProgram(srv, lxcProgram) < 0) {
+
+ rc = virNetServerAddProgram(srv, lxcProgram);
+ virObjectUnref(lxcProgram);
+ if (rc < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
@@ -1341,7 +1347,10 @@ int main(int argc, char **argv) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (virNetServerAddProgram(srv, qemuProgram) < 0) {
+
+ rc = virNetServerAddProgram(srv, qemuProgram);
+ virObjectUnref(qemuProgram);
+ if (rc < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
@@ -1379,7 +1388,10 @@ int main(int argc, char **argv) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (virNetServerAddProgram(srvAdm, adminProgram) < 0) {
+
+ rc = virNetServerAddProgram(srvAdm, adminProgram);
+ virObjectUnref(adminProgram);
+ if (rc < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
@@ -1487,10 +1499,6 @@ int main(int argc, char **argv) {
virStateCleanup();
}
- virObjectUnref(adminProgram);
- virObjectUnref(qemuProgram);
- virObjectUnref(lxcProgram);
- virObjectUnref(remoteProgram);
virObjectUnref(dmn);
virNetlinkShutdown();
--
2.17.1