diff options
author | Ian Campbell <ian.campbell@citrix.com> | 2012-09-17 11:16:59 +0100 |
---|---|---|
committer | Ian Campbell <ian.campbell@citrix.com> | 2012-09-17 11:16:59 +0100 |
commit | 5e61076e8f6e48856dacbd65499d6cb69d31976b (patch) | |
tree | 45d112091dee37ee15f44a307590762f3bb98e1a /tools/libxl/xl.c | |
parent | ae165a06593ad65c305889e3aaa0fefa6b8ed0b1 (diff) | |
download | xen-5e61076e8f6e48856dacbd65499d6cb69d31976b.tar.gz xen-5e61076e8f6e48856dacbd65499d6cb69d31976b.tar.bz2 xen-5e61076e8f6e48856dacbd65499d6cb69d31976b.zip |
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@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/libxl/xl.c')
-rw-r--r-- | tools/libxl/xl.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c index f31e836e87..ecbcd3bf1d 100644 --- a/tools/libxl/xl.c +++ b/tools/libxl/xl.c @@ -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; } |