[PATCH 3/5] libvirtd: Alter refcnt processing for domain server objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Whether the @srv/@srvAdm is added to the dmn->servers list or not,
the reference kept for the allocation can be dropped leaving just the
reference for being on the dmn->servers list be the sole deciding
factor when to really free the associated memory. The @dmn dispose
function (virNetDaemonDispose) will handle the Unref of the objects
during the virHashFree.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 daemon/libvirtd.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 73f24915df..5c47e49d48 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1065,6 +1065,7 @@ int main(int argc, char **argv) {
     char *remote_config_file = NULL;
     int statuswrite = -1;
     int ret = 1;
+    int rc;
     int pid_file_fd = -1;
     char *pid_file = NULL;
     char *sock_file = NULL;
@@ -1319,7 +1320,11 @@ int main(int argc, char **argv) {
         goto cleanup;
     }
 
-    if (virNetDaemonAddServer(dmn, srv) < 0) {
+    /* Add @srv to @dmn servers hash table and Unref to allow removal from
+     * hash table at @dmn disposal to decide when to free @srv */
+    rc = virNetDaemonAddServer(dmn, srv);
+    virObjectUnref(srv);
+    if (rc < 0) {
         ret = VIR_DAEMON_ERR_INIT;
         goto cleanup;
     }
@@ -1393,7 +1398,11 @@ int main(int argc, char **argv) {
         goto cleanup;
     }
 
-    if (virNetDaemonAddServer(dmn, srvAdm) < 0) {
+    /* Add @srvAdm to @dmn servers hash table and Unref to allow removal from
+     * hash table at @dmn disposal to decide when to free @srvAdm */
+    rc = virNetDaemonAddServer(dmn, srvAdm);
+    virObjectUnref(srvAdm);
+    if (rc < 0) {
         ret = VIR_DAEMON_ERR_INIT;
         goto cleanup;
     }
@@ -1509,8 +1518,6 @@ int main(int argc, char **argv) {
     virObjectUnref(qemuProgram);
     virObjectUnref(adminProgram);
     virNetDaemonClose(dmn);
-    virObjectUnref(srv);
-    virObjectUnref(srvAdm);
     virNetlinkShutdown();
     if (statuswrite != -1) {
         if (ret != 0) {
-- 
2.13.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux