]> git.ipfire.org Git - thirdparty/libvirt.git/commit
snapshot: fix memory leak on error
authorEric Blake <eblake@redhat.com>
Thu, 5 Apr 2012 19:15:03 +0000 (13:15 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 6 Apr 2012 14:39:34 +0000 (08:39 -0600)
commit1413560966eb07732b56dc2b83215462533656e5
tree8fe96a9bbbb994c8f153506e4d17e8555dad2d20
parent650da0e99c56f4142273f4e369ad02bd0c008765
snapshot: fix memory leak on error

Leak introduced in commit 0436d32.  If we allocate an actions array,
but fail early enough to never consume it with the qemu monitor
transaction call, we leaked memory.

But our semantics of making the transaction command free the caller's
memory is awkward; avoiding the memory leak requires making every
intermediate function in the call chain check for error.  It is much
easier to fix things so that the function that allocates also frees,
while the call chain leaves the caller's data intact.  To do that,
I had to hack our JSON data structure to make it easy to protect a
portion of an arbitrary JSON tree from being freed.

* src/util/json.h (virJSONType): Name the enum.
(_virJSONValue): New field.
* src/util/json.c (virJSONValueFree): Use it to protect a portion
of an array.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONTransaction): Avoid
freeing caller's data.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive):
Free actions array on failure.
src/qemu/qemu_driver.c
src/qemu/qemu_monitor_json.c
src/util/json.c
src/util/json.h