Skip to contentSkip to conversation

xl daemon: fix some memory leaks

PATCH Applied Stefano Stabellini 2 participants 2 messages Feb 17, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xl daemon: fix some memory leaks

xl daemon: fix some memory leaks

If we are watching multiple disks we have to free multiple waiters.

Free the event before continuing the loop.

Destroy the disk device returned by libxl_event_get_disk_eject_info.

tools/libxl/xl_cmdimpl.c +10 -4
diff -r 20b0f74bc31c tools/libxl/xl_cmdimpl.c
@@ -1338,7 +1338,7 @@ static int create_domain(struct domain_c
     const char *restore_file = dom_info->restore_file;
     int migrate_fd = dom_info->migrate_fd;
 
-    int fd;
+    int fd, i;
     int need_daemon = 1;
     int ret, rc;
     libxl_waiter *w1 = NULL, *w2 = NULL;
@@ -1607,7 +1607,10 @@ start:
             case LIBXL_EVENT_DOMAIN_DEATH:
                 ret = libxl_event_get_domain_death_info(&ctx, domid, &event, &info);
 
-                if (ret < 0) continue;
+                if (ret < 0) {
+                    libxl_free_event(&event);
+                    continue;
+                }
 
                 LOG("Domain %d is dead", domid);
 
@@ -1623,7 +1626,8 @@ start:
                         /* Otherwise fall through and restart. */
                     case 1:
 
-                        libxl_free_waiter(w1);
+                        for (i = 0; i < d_config.num_disks; i++)
+                            libxl_free_waiter(&w1[i]);
                         libxl_free_waiter(w2);
                         free(w1);
                         free(w2);
@@ -1659,8 +1663,10 @@ start:
                 }
                 break;
             case LIBXL_EVENT_DISK_EJECT:
-                if (libxl_event_get_disk_eject_info(&ctx, domid, &event, &disk))
+                if (libxl_event_get_disk_eject_info(&ctx, domid, &event, &disk)) {
                     libxl_cdrom_insert(&ctx, domid, &disk);
+                    libxl_device_disk_destroy(&disk);
+                }
                 break;
         }
         libxl_free_event(&event);
Applied
#1 lore raw

Stefano Stabellini writes ("[Xen-devel] [PATCH] xl daemon: fix some memory leaks"):

Quoted 1 line

xl daemon: fix some memory leaks

Applied, thanks.

Ian.