aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl/libxl_exec.c
diff options
context:
space:
mode:
authorGianni Tedesco <gianni.tedesco@citrix.com>2010-08-12 18:55:16 +0100
committerGianni Tedesco <gianni.tedesco@citrix.com>2010-08-12 18:55:16 +0100
commit94413e51b0558f0b55137328d51ce8c26dd358a0 (patch)
tree1716442ff500684121d4da656788c812ce35606a /tools/libxl/libxl_exec.c
parentdb6b874fcd1430219176a4f86c2bf21dc4946388 (diff)
downloadxen-94413e51b0558f0b55137328d51ce8c26dd358a0.tar.gz
xen-94413e51b0558f0b55137328d51ce8c26dd358a0.tar.bz2
xen-94413e51b0558f0b55137328d51ce8c26dd358a0.zip
xl: Implement per-API-call garbage-collection lifetime
Currently scratch variables allocated by libxl have the same lifetime as the context. While this is suitable for one off invocations of xl. It is not so great for a daemon process linking to libxl. In that case there will be prolific leakage of heap memory. My proposed solution involves create a new libxl_gc structure, which contains a pointer to an owning context as well as the garbage collection data. Top-level library functions which expect to do a lot of scratch allocations put gc struct on the stack and initialize it with a macro. Before returning they then call libxl_free_all on this struct. This means that static helper functions called by such functions will usually take a gc instead of a ctx as a first parameter. The patch touches almost every code-path so a close review and testing would be much appreciated. I have tested with valgrind all of the parts I could which looked non-straightforward. Suffice to say that it seems crash-free even if we have exposed a few real memory leaks. These are for cases where we return eg. block list to an xl caller but there is no appropriate block_list_free() function to call. Ian Campbells work in this area should sew up all these loose ends. Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com> committer: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Diffstat (limited to 'tools/libxl/libxl_exec.c')
-rw-r--r--tools/libxl/libxl_exec.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c
index c488e38975..5210c4f98a 100644
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -100,7 +100,7 @@ int libxl_spawn_spawn(libxl_ctx *ctx,
libxl_spawn_starting *for_spawn = starting->for_spawn;
if (for_spawn) {
- for_spawn->what = libxl_strdup(ctx, what);
+ for_spawn->what = strdup(what);
if (!for_spawn->what) return ERROR_NOMEM;
}
@@ -140,10 +140,12 @@ static void report_spawn_intermediate_status(libxl_ctx *ctx,
int status)
{
if (!WIFEXITED(status)) {
+ char *intermediate_what;
/* intermediate process did the logging itself if it exited */
- char *intermediate_what = libxl_sprintf(ctx,
- "%s intermediate process (startup monitor)",
- for_spawn->what);
+ if ( asprintf(&intermediate_what,
+ "%s intermediate process (startup monitor)",
+ for_spawn->what) < 0 )
+ intermediate_what = "intermediate process (startup monitor)";
libxl_report_child_exitstatus(ctx, XL_LOG_ERROR, intermediate_what,
for_spawn->intermediate, status);
}