libxl: fix transaction leak in logdirty error path
PATCH 1/1 libxl: fix transaction leak in logdirty error path
libxl__domain_suspend_common_switch_qemu_logdirty would leak t if there was an error. Fix this.
Also, document the intended usage for libxl__xs_transaction_* in the doc comment in libxl_internal.h.
--- tools/libxl/libxl_dom.c | 1 + tools/libxl/libxl_internal.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-)
tools/libxl/libxl_dom.c +1 -0
@@ -627,6 +627,7 @@ void libxl__domain_suspend_common_switch_qemu_logdirty out:LOG (ERROR ,"logdirty switch failed (rc=%d), aborting suspend" ,rc); +libxl__xs_transaction_abort (gc, &t);switch_logdirty_done (egc,dss,-1 ); }
tools/libxl/libxl_internal.h +36 -0
@@ -543,6 +543,42 @@ int libxl__xs_rm_checked(libxl__gc *gc, xs_transaction_t t, const char *path);* +1 commit conflict; transaction has been destroyed and caller * must go round again (call _start again and retry) * 0 committed successfully +* +* The intended usage pattern looks like this: +* int some_function() +* { +* int rc; +* xs_transaction_t t = 0; +* // other initialisations +* +* // do whatever you need to do before the xenstore stuff +* // errors? set rc and goto out. +* +* for (;;) { +* rc = libxl__xs_transaction_start(gc, &t); +* if (rc) goto out; +* +* // do your work here, including all xenstore reads and writes +* // libxl__xs_*_checked are useful; pass them t. +* // errors? set rc and goto out. +* +* rc = libxl__xs_transaction_commit(gc, &t); +* if (!rc) break; +* if (rc<0) goto out; +* } +* +* // now the xenstore transaction succeeded +* // do whatever else you need to do +* // errors? set rc and goto out. +* +* return something; +* +* out: +* // other cleanups +* libxl__xs_transaction_abort(gc, &t); +* // other cleanups +* return rc; +* } */ int libxl__xs_transaction_start (libxl__gc *gc,xs_transaction_t *t);int libxl__xs_transaction_commit (libxl__gc *gc,xs_transaction_t *t);
Signature · 1 line
tg: (c3a0480..) t/xen/xl.fix.logdirty-trans-leak (depends on: t/xen/xl.bootloader.fix.no-blunder-on)
Quoted 8 lines · Ian Jackson
libxl__domain_suspend_common_switch_qemu_logdirtywould leak t if there was an error. Fix this.Also, document the intended usage for libxl__xs_transaction_* in the doc comment in
libxl_internal.h.Reported-by Ian Campbell <[email protected]>Signed-off-by Ian Jackson <[email protected]>
Quoted 65 lines
--- tools/libxl/libxl_dom.c | 1 + tools/libxl/libxl_internal.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-)tools/libxl/libxl_dom.c +1
-0@@ -627,6 +627,7 @@ void libxl__domain_suspend_common_switch_qemu_logdirty out:LOG (ERROR ,"logdirty switch failed (rc=%d), aborting suspend" ,rc); +libxl__xs_transaction_abort (gc, &t);switch_logdirty_done (egc,dss,-1 ); }tools/libxl/libxl_internal.h +36
-0@@ -543,6 +543,42 @@ int libxl__xs_rm_checked(libxl__gc *gc, xs_transaction_t t, const char *path);* +1 commit conflict; transaction has been destroyed and caller * must go round again (call _start again and retry) * 0 committed successfully +* +* The intended usage pattern looks like this: +* int some_function() +* { +* int rc; +* xs_transaction_t t = 0; +* // other initialisations +* +* // do whatever you need to do before the xenstore stuff +* // errors? set rc and goto out. +* +* for (;;) { +* rc = libxl__xs_transaction_start(gc, &t); +* if (rc) goto out; +* +* // do your work here, including all xenstore reads and writes +* // libxl__xs_*_checked are useful; pass them t. +* // errors? set rc and goto out. +* +* rc = libxl__xs_transaction_commit(gc, &t); +* if (!rc) break; +* if (rc<0) goto out; +* } +* +* // now the xenstore transaction succeeded +* // do whatever else you need to do +* // errors? set rc and goto out. +* +* return something; +* +* out: +* // other cleanups +* libxl__xs_transaction_abort(gc, &t); +* // other cleanups +* return rc; +* } */ int libxl__xs_transaction_start (libxl__gc *gc,xs_transaction_t *t);int libxl__xs_transaction_commit (libxl__gc *gc,xs_transaction_t *t);
Ian Campbell
AppliedQuoted 11 lines · Ian Campbell
Quoted 8 lines · Ian Jackson
libxl__domain_suspend_common_switch_qemu_logdirtywould leak t if there was an error. Fix this.Also, document the intended usage for libxl__xs_transaction_* in the doc comment in
libxl_internal.h.Reported-by Ian Campbell <[email protected]>Signed-off-by Ian Jackson <[email protected]>Acked-by Ian Campbell <[email protected]>
Applied, squashing some trailing whitespace as I went.
Quoted 73 lines
Quoted 56 lines
--- tools/libxl/libxl_dom.c | 1 + tools/libxl/libxl_internal.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-)tools/libxl/libxl_dom.c +1
-0@@ -627,6 +627,7 @@ void libxl__domain_suspend_common_switch_qemu_logdirty out:LOG (ERROR ,"logdirty switch failed (rc=%d), aborting suspend" ,rc); +libxl__xs_transaction_abort (gc, &t);switch_logdirty_done (egc,dss,-1 ); }tools/libxl/libxl_internal.h +29
-0@@ -543,6 +543,42 @@ int libxl__xs_rm_checked(libxl__gc *gc, xs_transaction_t t, const char *path);* +1 commit conflict; transaction has been destroyed and caller * must go round again (call _start again and retry) * 0 committed successfully +* +* The intended usage pattern looks like this: +* int some_function() +* { +* int rc; +* xs_transaction_t t = 0; +* // other initialisations +* +* // do whatever you need to do before the xenstore stuff +* // errors? set rc and goto out. +* +* for (;;) { +* rc = libxl__xs_transaction_start(gc, &t); +* if (rc) goto out; +* +* // do your work here, including all xenstore reads and writes +* // libxl__xs_*_checked are useful; pass them t. +* // errors? set rc and goto out. +* +* rc = libxl__xs_transaction_commit(gc, &t); +* if (!rc) break; +* if (rc<0) goto out; +* } +* +* // now the xenstore transaction succeeded +* // do whatever else you need to do +* // errors? set rc and goto out. +* +* return something; tools/libxl/libxl_internal.h int libxl__xs_rm_checked(libxl__gc *gc, xs_transaction_t t, const char *path); · line 584
Quoted 10 lines
tools/libxl/libxl_internal.h +7
-0+* +* out: +* // other cleanups +* libxl__xs_transaction_abort(gc, &t); +* // other cleanups +* return rc; +* } */ int libxl__xs_transaction_start (libxl__gc *gc,xs_transaction_t *t);int libxl__xs_transaction_commit (libxl__gc *gc,xs_transaction_t *t);_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel