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

[Xen-changelog] [xen-unstable] xl: free libxl context, logger and lockfile using atexit handler


  • To: xen-changelog@xxxxxxxxxxxxxxxxxxx
  • From: Xen patchbot-unstable <patchbot@xxxxxxx>
  • Date: Mon, 17 Sep 2012 21:55:10 +0000
  • Delivery-date: Mon, 17 Sep 2012 21:55:24 +0000
  • List-id: "Change log for Mercurial \(receive only\)" <xen-changelog.lists.xen.org>

# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1347877019 -3600
# Node ID 98ca21138ce8f60a1a862860f9d6a709a5235a0f
# Parent  51408c3528030309e8f064bf6a3c96b37de7dc96
xl: free libxl context, logger and lockfile using atexit handler

xl frequently just calls exit(3), especially on error. Try to clean
up some of our global state to make tools like valgrind more useful.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Committed-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---


diff -r 51408c352803 -r 98ca21138ce8 tools/libxl/xl.c
--- a/tools/libxl/xl.c  Mon Sep 17 10:09:59 2012 +0200
+++ b/tools/libxl/xl.c  Mon Sep 17 11:16:59 2012 +0100
@@ -191,6 +191,22 @@ void xl_ctx_alloc(void) {
     libxl_childproc_setmode(ctx, &childproc_hooks, 0);
 }
 
+static void xl_ctx_free(void)
+{
+    if (ctx) {
+        libxl_ctx_free(ctx);
+        ctx = NULL;
+    }
+    if (logger) {
+        xtl_logger_destroy((xentoollog_logger*)logger);
+        logger = NULL;
+    }
+    if (lockfile) {
+        free(lockfile);
+        lockfile = NULL;
+    }
+}
+
 int main(int argc, char **argv)
 {
     int opt = 0;
@@ -229,6 +245,8 @@ int main(int argc, char **argv)
     logger = xtl_createlogger_stdiostream(stderr, minmsglevel,  0);
     if (!logger) exit(1);
 
+    atexit(xl_ctx_free);
+
     xl_ctx_alloc();
 
     ret = libxl_read_file_contents(ctx, XL_GLOBAL_CONFIG,
@@ -274,8 +292,6 @@ int main(int argc, char **argv)
     }
 
  xit:
-    libxl_ctx_free(ctx);
-    xtl_logger_destroy((xentoollog_logger*)logger);
     return ret;
 }
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.